I am trying to save struct to file and load it but when I load it I can't get field names

조회 수: 3 (최근 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
Jonas 2022년 7월 18일
what is the output of fieldnames(queries)? could you also supply the mat file contianing the struct?

댓글을 달려면 로그인하십시오.

채택된 답변

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