MATLAB: Opening mat files with uiopen and copying data to array

MATLABuiopen mat file array cell

I have some mat files organized as cell arrays. All my mat files have the same structure and have progressive names, like MyFile_001, MyFile_002 and so on.
Copying data to arrays is an easy operation, such as
load('MyFile_001.mat')
Data1 = MyFile_001.Y(1).Data;
Data2 = MyFile_001.Y(2).Data;
but what if I want to choose which mat file to open instead of 'MyFile_001'?
The first row becomes
uiopen('load')
so I choose through GUI the file to be opened. How can I save data to arrays now?

Best Answer

It seems that whoever created those .mat files unfortunately named each structure with the same name as the filename, which just makes accessing the data more complex (it is much simpler to process a sequence of .mat files when their variable names are the same for each file).
Assuming that each .mat file contains exactly one variable (i.e. the structure), then you can work with these badly designed .mat files by ignoring the variable name entirely:
T = load(...);
T = struct2cell(T);
Data1 = T{1}.Y(1).Data;
Data2 = T{1}.Y(2).Data;
See also: