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

1 visualización (últimos 30 días)
John
John el 25 de Sept. de 2014
Comentada: John el 29 de Sept. de 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

Respuesta aceptada

Guillaume
Guillaume el 25 de Sept. de 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 comentario
John
John el 29 de Sept. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by