I am trying to save struct to file and load it but when I load it I can't get field names
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hadasa kaufman
am 18 Jul. 2022
Kommentiert: hadasa kaufman
am 18 Jul. 2022
hi,
I am saving structure arrays to file in one matlab script and I can find the mat file and to open it.
save('/sci/labs/mbreker/hadasak/icore-data/MAPS_seq/Data/example_July_2016/Analysis/subjects_queries.mat','subjects','queries');
I am open it in another matlab script
queries=load('/sci/labs/mbreker/hadasak/icore-data/MAPS_seq/Data/example_July_2016/Analysis/subjects_queries.mat','queries');
subjects=load('/sci/labs/mbreker/hadasak/icore-data/MAPS_seq/Data/example_July_2016/Analysis/subjects_queries.mat','subjects');
but then when I am trying to insert into the struct by fieldnames
outfilename=sprintf('%s/%s_Alt_analysis_%s',getfield(queries,{1},'directory'),proj_tag,datelabel);
or
outfilename=sprintf('%s/%s_Alt_analysis_%s',queries(1).directory,proj_tag,datelabel);
I get this error:
Unrecognized field name "directory".
Error in getfield (line 69)
f = f.(field);
another thing that I notic is that when I open the .mat file (not load it, just reviewe of the file in matlab), I can see the fields.
I will be happy to get help,
thanks!
1 Kommentar
Jonas
am 18 Jul. 2022
what is the output of fieldnames(queries)? could you also supply the mat file contianing the struct?
Akzeptierte Antwort
Stephen23
am 18 Jul. 2022
Bearbeitet: Stephen23
am 18 Jul. 2022
Load the data like this:
F = '/sci/labs/mbreker/hadasak/icore-data/MAPS_seq/Data/example_July_2016/Analysis/subjects_queries.mat';
S = load(F);
queries = S.queries;
subjects = S.subjects;
and everything will work just as you want. Note that the output of LOAD() is not your data arrays, but is always a scalar structure that contains all of your data arrays. So you simply need to refer to its fields (which are your data arrays).
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!