I would like to make a loop that accumulates an array of structures, such as
array=struct([]); % The docs imply that this should work
for i=1:nst=CreateAStruct(i);array(i)=st;end;
But…this doesn't work, I get the error, "Subscripted assignment between dissimilar structures." on the first pass through the loop. Instead the only way I've found to do this is the following.
for i=1:n st=CreateAStruct(i); if i==1 array=st; else array(i)=st; end;end;
Is there a nicer way to do this?
Best Answer