Take the following custom C# class as an example, it represents a point:
public class Point
{
// Attributes:
double x;
double y;
// Constructor:
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
// Methods:
public void SetX(double x)
{
this.x = x;
}
public void SetY(double y)
{
this.y = y;
}
public double GetX()
{
return this.x;
}
public double GetY()
{
return this.y;
}
}
I would like to adapt this same class to MATLAB. My goal is to implement the Set and Get methods and the Constructor, as similar as possible to the C# way.
I am aware that MATLAB does not allow self-reference, as I read on this question. However, I know that I should problably want to start the class with the following header:
classdef Point < handle
I read about this here and here. This statement will declare my custom Point
class as the MATLAB handle
class, by having it inherit from the handle superclass. I understand that this will allow me to implement the Set/Get functionality that I am trying to emulate, as well as for the Constructor.
This is what I have so far:
classdef Point < handle
% Attributes
properties (Access = private)
x = [];
y = [];
end
% Methods
methods
% Constructor: First method, must have the same name as the class.
function Point(x,y)
end
% Set and Get methods:
function SetX(x)
end
...
end
end
From this point on, I don't know how to continue.