MATLAB: Automating script using uiload

uiload

I have multiple .mat (8760×4 table) files which I want to do the same analysis on, one at a time. The script I've written works well with one of these .mat files, the one I used when I wrote the script. However, now I want to be able to use the script with all my .mat
This is what the code looks like now.
load('examplefile') %imports abc table to the workspace
xsource=linspace(datenum('01/01/14 00:00','dd/mm/yy HH:MM'),datenum('31/12/14 23:00','dd/mm/yy HH:MM'),8760); %creates a vector with datnum to use as x-axis
frb=abc.Vrde; %Gets column Vrde from table abc
qual=zeros(length(frb),1); %creates a vector with zeros with the same length as frb
ts=timeseries(frb,xsource,qual); %creates a timeseries with frb,xsource,qual
ts.QualityInfo.Code= [0 1 2 3 4 5]; %different quality flags
ts.QualityInfo.Description= {'A' 'B' 'C' 'D' 'E' 'F' }; % Display name of the quality flags
When I run the script, I want Matlab to ask me which file to load. In order to do so I used uiload. This lets me chose which ever .mat file I want to perform the analysis on. This loads a table into the workspace, and it is at this point I get stuck. There is probably an easy way but I can't really see it.
Every .mat file has the same structure, So what I need to automate is creating the
frb=abc.Vrde
But with instead of abc I want to use the name of the table that was loaded using uiload. The rest of the script is based on the timeseries ts.
Is there any way to work around this?

Best Answer

jakob,
You can get the variables loaded in your workspace with the who command.
Try out this example:
m2 = magic(2);
m3 = magic(3);
myVars = who;
In case your workspace already has several variables, you can directly get the variable names inside your .mat file like this:
myVars = who('-file','mydata.mat');
Now myVars contains the variables names inside of mydata.mat.
Assuming you have a way of identifying the right variable name from within myVars, you can extract Vrde like this:
myColumn = eval([myVars{someIndex},'.Vrde']);
Related Question