How to create a cell array with the content of a component of a structure?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
José Antonio Caldas de la Vega
am 8 Jul. 2020
Kommentiert: Matt J
am 8 Jul. 2020
I have a structure called sFiles and I want to put the information that is inside sFiles.FileName inside a cell array called your cell,
I have this code:
for i=1:1:length(sFiles)
yourcell={sFiles(i).FileName};
end
Does anybody know why is not working?
Thanks
0 Kommentare
Akzeptierte Antwort
Matt J
am 8 Jul. 2020
Bearbeitet: Matt J
am 8 Jul. 2020
It is not working because in your for-loop, yourcell is never indexed by the loop variable i, so the loop code has no idea where within yourcell you want to put things.
A for-loop is, in any case, unnecessary. The whole task can be done in a single command as follows:
yourcell={sFiles.FileName};
2 Kommentare
Matt J
am 8 Jul. 2020
You're quite welcome, but please Accept-click the answer to signify that your question is resolved.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!