How Can I create struct field in a loop?
Ältere Kommentare anzeigen
Hello to all,
I have a problem with the struct. I have two nested for loops. With the innermost one I create a struct called 'strutt'. Once I get out of the internal one I have to allocate the whole structure to another structure in the different fields. The problem is that the field is always overwritten. here is the code. Can you help me?
for j=1:4
for i=1:10
strutt.a(1,i)=importdata(...)
strutt.b(1,i)=importdata(...)
..
end
soluz=struct(sprintf('hi%d',j),strutt);
end
2 Kommentare
Stephen23
am 18 Jan. 2020
Rather than forcing numbers into fieldnames it would probably be more efficient to use a non-scalar structure
Gianmarco Manzo
am 19 Jan. 2020
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!