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!

采纳的回答

Stephen23
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 CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by