MATLAB: How to use structures as properties of a matlab class

code generationMATLABobject oriented programmingoop

Dear reader,
I would like to be able to use structures inside classdef and I do now know how to do it. Here is a toy example of what I would like:
classdef dummy1
properties
S.a = 0;
S.b = linspace(1,2,1e1);
S.c = [1 2 3];
P.d = 0;
P.e = 1;
end
methods
%constructor
function obj = dummy1()
obj;
end
end
end
Notice the two structures S and P defined inside this class.
However I get an error when running:
dummy1()
Any help is highly appreciated. Once I get through with this, the next challenge would be to have this class ready for code generation.
Thank you

Best Answer

The declaration and initialisation of a property in a class must follow the form:
variablename = value;
You can assign a structure as that value, but that structure needs to be fully formed, for example with struct (or cell2struct, or a function that return a struct, etc.):
classdef dummy1
properties
S = struct('a', 0, 'b', linspace(1, 2, 10), 'c', [1 2 3]);
P = struct('d', 0, 'e', 1);
end
end