MATLAB: How to make the plot function use a string as an argument

argumentMATLABplotstring

Hi everyone.
I am currently writing a small script which should generate some plots, save them and generate some LaTeX code afterwards to add them to a little report.
What I have is this: I have 11x11x21 matices called: pos_x,pos_y,div_x,div_y … All in all it's 9 different matrices containing my plot data. Now what I want is I want to plot a specific row, a line and a layer of each and every matrix (at the beginning I specify which row, line and which layer) for every matrix.
All in all, if I specify that at the beginning I end up with 27 Plots (3 Variations*9 Matrices). Now what I did was: I created a script that generates all the necessary plot arguments as strings and puts them inside the cell. Now I made a loop which should simply take the input of the cell, put it as an argument for the plot function BUT this simply does not work.
The lower part of my script looks like this:
for ii =1:3
for kk=1:9
file_name = [variable_names{kk},index_names{ii}];
temp_plot_name1 = ['0:10,',variable_names{kk},'(1:11,index2+1,index3+11)*1000'];
temp_plot_name2 = ['0:10,',variable_names{kk},'(index1+1,1:11,index3+11)*1000'];
temp_plot_name3 = ['-10:10,',variable_names{kk},'(index1+1,index2+1,1:21)*1000'];
temp_plot_names = {temp_plot_name1,temp_plot_name2,temp_plot_name3};
f = figure('visible','off');
plot(temp_plot_names{ii});
grid on;
title(titles{ii});
xlabel(xlabels{ii});
ylable(ylabels{kk});
matlabfrag(file_name);
fprintf(tex_code,['\\psfragfig{D:/Bilder/',file_name,'}\n']);
end
end
Now, the variable_names and index_names are defined above the script. The problem is that Plot now treats the input argument as a string.
So instead of doing this: plot(0:10,pos_x(1:11,index2+1,index3+11)*1000) it does plot('0:10,pos_x(1:11,index2+1,index3+11)*1000') and gives an error.
So after this long description my question is:
How can I make the plot function understand my argument properly?
Kind regards, Kevin

Best Answer

Example:
V = rand(100,1);
string = 'V(1:10)';
plot(1:10, eval(string))