On Jan 4, 2013, at 5:26 PM, Michael Goffioul wrote:
> Can anyone test the following in Matlab.
>
> Have a class defined in ClassA.m as:
>
> classdef ClassA < handle
> properties
> x = 1;
> end
> methods
> function obj = ClassA (x)
> obj.x = x;
> end
> end
I had a few minutes to get back to this today. Looks like I'm helping with the easy parts ;-)
You missed an "end"
classdef ClassA < handle
properties
x = 1;
end
methods
function obj = ClassA (x)
obj.x = x;
end
end
end
> At the prompt, execute:
>
> a(2,2) = ClassA (2)
a(2,2) = ClassA (2)
Error using ClassA (line 7)
Not enough input arguments.
Of course, use this instead:
classdef ClassA < handle
properties
x = 1;
end
methods
function obj = ClassA (x)
if nargin > 0
obj.x = x;
end
end
end
end
Michael.