how to avoid using a name to a specific file in GUI
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
We are creating a GUI in Matlab guide. The problem I have is that I am accesing the data from a structure within structure which has fields such as data and time (which I need). The code is written in such a way that the name of the paritucular loaded field is always in the path, how to avoid this?
Here is how I am accesing the data:
[filename,pathname]=uigetfile('*.mat') %,'Select One or More Files','MultiSelect', 'on')
MyData= load(filename);
handles.MyData = MyData;
MyData=handles.MyData;
But then I am eding up with this structure within structure with a code that only works for a specific filename:
time=MyData.Specificname.fieldA(1,1)
This is what I have tried without success:
% fn=char(fieldnames(MyData))
% s=sprintf('h.SD=MyData.%s',fn);
% eval(s);
% h.SD=fn
Thanks in advance!
댓글 수: 1
채택된 답변
Stephen23
2019년 7월 30일
편집: Stephen23
2019년 7월 30일
Your explanation is not clear if you know Specificname in advance or not, or how many variables there are saved in the .mat file. None of the names that you use in your example code match the names that you use in your explanation. Remember that we can only read what you write here.
If there is only one variable in the .mat file then you can do this:
[F,P]=uigetfile('*.mat')
S = load(fullfile(P,F));
C = struct2cell(S);
T = C{1};
T.data
T.time
If there are multiple fields, then you could use dynamic fieldnames, e.g.
S = load(fullfile(P,F));
T = S.('Specificname');
T.data
T.time
Note that if Specificname is different in each .mat file then the data has not been designed very well. It is much easier to parse multiple mat files when then variable names are the same in each file.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!