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

1 回表示 (過去 30 日間)
John
John 2014 年 9 月 25 日
コメント済み: John 2014 年 9 月 29 日
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 Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by