Matlab: Using detrend(var) but using the variable referenced in the string saved in 'var' -
my code loads in .mat file number of data arrays in it. user names arrays in file want, tell code variable names through gui, saves array names string in variable.
i need perform detrend() on these arrays before plotting them, detrend function references variable name rather array.
example: ... varname = get(handles.edit1,'string') ; %'data1' ... load (file.mat) %contains data arrays
data = detrend(double(varname)); ...
instead of load('file.mat')
pollutes code's namespace user data, use
userdata = load('file.mat');
or even
userdata = load('file.mat', varname);
after this, can do
userdata.(varname)
to access variable name in string varname
, contents read file file.mat
.
you use fieldnames(userdata)
find out array names, instead of requiring user remember , type them in.
Comments
Post a Comment