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

1 次查看(过去 30 天)
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

采纳的回答

Guillaume
Guillaume 2014-9-25
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 个评论
John
John 2014-9-29
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by