automating script using uiload
Mostra commenti meno recenti
I have multiple .mat (8760x4 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?
2 Commenti
Kirby Fears
il 20 Gen 2016
Modificato: Kirby Fears
il 20 Gen 2016
Is the issue that you have a collection of .mat files that each have analogous data in the "abc" table, but the name of "abc" is different within each .mat file?
You need to know something about the name in order to make this work. Is your table "abc" the only thing in each .mat file? Otherwise, do you have a way to identify the table, such as a naming convention?
E.g. is abc always called ['results_',datestr] ?
jakob ekwall
il 20 Gen 2016
Modificato: jakob ekwall
il 20 Gen 2016
Risposta accettata
Più risposte (1)
Steven Lord
il 20 Gen 2016
Inside a function I would ALWAYS call LOAD with an output argument.
data = load('mymatfile.mat');
listOfVariablesFromMatfile = fieldnames(data);
firstVariable = data.(listOfVariablesFromMatfile{1});
Categorie
Scopri di più su Tables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
