I am trying to save struct to file and load it but when I load it I can't get field names
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jonas
2022-7-18
what is the output of fieldnames(queries)? could you also supply the mat file contianing the struct?
采纳的回答
Stephen23
2022-7-18
编辑:Stephen23
2022-7-18
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).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!