MATLAB: How to avoid using a name to a specific file in GUI

guidematlab gui

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!

Best Answer

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.