I know how to initialise an array of objects:
arrayOfA(3,2) = ClassA();
for i = 1:3
for j = 1:2
arrayofA(i,j) = ClassA(...);
end
end
but when I try this for a property:
classdef ClassB
properties
arrayOfA;
...
end
methods
%% Constructor
function b = ClassB(...)
b.arrayOfA(3,2) = ClassA(); % Error!
...
end
end
I get the exception Conversion to double from ClassA is not possible.
I have read that when a default value for a property is not provided, it is initialised to an empty array of doubles. This explains the exception, but how do I set the default value of arrayOfA such that I can fill it with objects?
I have tried:
properties
arrayOfA(3,2) = ClassA;
but this gives the exception Unbalanced or unexpected parenthesis or bracket.
Edit: I am using MATLAB R2015b, which turns out to affect the solution - see below.
emptyshould work in both, if that does what you need.