How to save struct data in for loop
Ältere Kommentare anzeigen
Hi,
I am working in a for loop where for each iteration I get a new structure data with 3 fields in all of them. How do I store all of these data points so that I could use them together? I tried working with the following format but I am getting the error "Subscripted assignment between dissimilar structures."
The m.get_data() returns a struct of three fields each containg 1024 values.
for i=1:10
data_struct(i)=m.get_data();
end
5 Kommentare
Walter Roberson
am 23 Okt. 2020
Bearbeitet: Walter Roberson
am 23 Okt. 2020
You have a left-over value for data_struct in your workspace. Clear it, or better yet use a different variable name.
Suman Chatterjee
am 23 Okt. 2020
Walter Roberson
am 23 Okt. 2020
Also note that in order to assign an entire struct into an existing struct array, the structure fields must be in exactly the same order between the two.
Suman Chatterjee
am 23 Okt. 2020
Walter Roberson
am 23 Okt. 2020
Use dynamic structure names so your data_struct is a struct with multiple field names. Then use save() with the -struct option; that will create one variable name in the .mat file for each field name in the struct.
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!