MATLAB: Loading a variable from deferent .mat files selected using GUI matlab

ramzi dra

how can i load a double from a mat file that i selected using push button in gui matlab , whatever the matfile i be able to extract an load a double from it and use it ex: i have a mat file called 1.mat and another 2.mat
whos -file 1.mat
Name Size Bytes Class Attributes
X1RPM 1x1 8 double
X1_BA_time 122136x1 977088 double
X1_DE_time 122136x1 977088 double
X1_FE_time 122136x1 977088 double
dt=new.X1_DE_time;
2nd mat file 2.mat
whos -file 2.mat
Name Size Bytes Class Attributes
X2RPM 1x1 8 double
X2_BA_time 122136x1 977088 double
X2_DE_time 122136x1 977088 double
X2_FE_time 122136x1 977088 double
dt=new.X2_DE_time;
using GUI now 1st push putton
function Data_Callback(~, ~, handles)
[filename, pathname] = uigetfile({'*.mat'},'File Selector');
set(handles.text5,'String', filename)% showing full path name
handles.data=load([pathname, filename]);
data=filename;
setappdata(0,'data',data);
2nd push putton
function ok_Callback(hObject, eventdata, handles)
new=load(getappdata(0,'data'));
now i have the problem , how can i load de time whatever the mat file selected
dt=new.X1 or X2 or,...._DE_time;

Best Answer

>> new.X1_BA_time = 1:3;
>> new.X1_DE_time = 4:6;
>> new.X1_FE_time = 7:9;
>> C = fieldnames(new);
>> X = cellfun('isempty',regexp(C,'^X\d+_DE_time$'));
>> dt = new.(C{~X})
dt =
4 5 6