Plotting data set, within a function, via a file list

1 Ansicht (letzte 30 Tage)
John
John am 25 Sep. 2014
Kommentiert: John am 29 Sep. 2014
Hello All,
I have a situation where I need to input a dataset number to a function and have that function filter all the variables and plot a select few that pertain to that dataset. I have the filtering portion working correctly, but i can for the life of me figure out how to get it to plot.
Here is a really simplified version of what im trying to do in my base workspace lets say I have some time domain data
1_A={1 2 3;4 7 3};
2_A={1 2 3;5 1 9};
2_B={1 2 3;4 5 0};
plotThis(2)
and then a function
function []=PlotThis(DataSet);
fileList = evalin('base','who');
(do a whole bunch of stuff which looks at fileList and picks out data sets associated with dataSet#2 producing a new list of just those I want to operate on which woudl look like this)
dataSetName = {2_A;2_B} for instance
for i=1:length(dataSetName)
evalin('base','plot(dataSetName{i})',dataSetName);
this is where my problem is, how to I get matlab to realize the string '2_A' in dataSetName is actually a variable in the base workspace?
end
end
Any and all help is appreciated

Akzeptierte Antwort

Guillaume
Guillaume am 25 Sep. 2014
Wouldn't
plot(evalin('base', dataSetName{i}));
work? Assuming that 1_A, 2_A, etc. are actually vectors not cell arrays.
Alternatively:
evalin('base', sprintf('plot(%s)', dataSetName{i}));
  1 Kommentar
John
John am 29 Sep. 2014
Guillaume,
Thank you for your help, the first suggestion worked perfectly. =) It looks so easy now that i see how it works. Maybe my question and your answer will help someone else oneday.
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by