Initializing Array of Structures/Objects
Mostrar comentarios más antiguos
I simply want to set each struct in a struct-array. I set structarray to [] as it is an object property in my case, where it is being initialized as emtpy array. My first approach looks like:
structarray = [];
for i=1:10
structarray(i) = struct('index', i);
end
I get the following error: 'The following error occurred converting from struct to double: Error using double Conversion to double from struct is not possible.'
I can use an if else check and set the first element by:
structarray = struct('index', i);
On http://www.ece.northwestern.edu/CFS/local-apps/matlabhelp/base/relnotes/matlab/matlab1212.html it reports that setting structarray(1) throws this error.
Is there any easy way to write this straightforward similar to my code above?
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 6 de Sept. de 2015
structarray = struct('index', repmat({[]}, 1, 10));
Categorías
Más información sobre Structures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!