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 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