Looping through list of files to access variable names
Ältere Kommentare anzeigen
Hi all, this might be very simple but i've been struggling to get solution for this all day. I have loaded in my mat file which contains variables e.g wind(500x1), temp(500x1), waves(500x1). I have created a list of the variables in the mat file using who. What i want to do is use the list of files to select each variable in turn, interpolate it and then define a new variable. I can't seem to get the cell string created by who to identify the variable in the workspace.
Licor_Datetime and Und_Datetime(500x1) are just two time vectors. I have no issue with the interpolation.
Any help would be appreciated
Richard
load ('C:\Users\rps207\Documents\MATLAB\CO2 NSOP output analysis\Data\DY030underway.mat')
Varnames = who('-file','C:\Users\rps207\Documents\MATLAB\CO2 NSOP output analysis\Data\DY030underway.mat');
%
for i=1:numel(Varnames)
Varnames_new= interp1(Und_Datetime,Varnames(i),Licor_Datetime);
end
Basic solution with no loops, tedious for 50+ variables
Salinity_new= interp1(Und_Datetime,Varnames(i),Licor_Datetime);
Waves_new= interp1(Und_Datetime,Waves,Licor_Datetime);
Temperature_new= interp1(Und_Datetime,Temperature,Licor_Datetime);
1 Kommentar
Stephen23
am 6 Jun. 2016
@Richard Sims: Walter Roberson's answer is the best way to solve your question. In future you should keep in mind that it although it is possible to access variables like that, in practice it is very slow and buggy, and should be avoided. Here is an explanation of why you should not try to create or access lots of variable names dynamically:
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!