Using values from an array as titles in generated figures

20 visualizaciones (últimos 30 días)
David
David el 18 de Ag. de 2014
Editada: Adam el 18 de Ag. de 2014
Hi,
So I have some code that runs through some data given to it multiple times, and creates figures based upon different apsects of the code.
What I want it to do now is to use an array (or another method) to name the figures base upon what run of the program it is on.
My current code is:
cd('....')
output_file='....'
var_name = ['VAR1, VAR2, VAR3, VAR4'];
for count_1 = 1:4;
current_var = var_name(count_1);
for count_2 = 1:10;
data = load(....)
current_data = count_1 + 4;
data_1 = data(:,1);
data_2 = data(:,2);
data_3 = data(:,current_data);
data_figure= figure('Visible','off');
axes1 = axes('Parent', data_figure, 'ZGrid', 'on', 'YGrid', 'on');
view(axes1,[0.5 90]);
xlim(axes1,[-0.01 0.25]);
hold(axes1, 'all');
surf(data_reshape_1,data_reshape_2,data_reshape_3, 'Edgecolor', 'none');
colorbar;
%ISSUE IN THE NEXT FEW LINES
title([num2str(count_2),'ns: ',[num2str(current_var),'.....']]);
xlabel('.....');
ylabel('.....');
ylabel(colorbar, [num2str(current_var)]);
set(gca, 'XGrid', 'off');
end
end
Everything works fine, apart from the fact that instead of using the values of what is in var_name in turn, it takes the letters from the first value in the array, i.e V, A, R, 1 and not the desired, VAR1, VAR2, VAR3, VAR4
Any help would be great.

Respuestas (2)

Adam
Adam el 18 de Ag. de 2014
Editada: Adam el 18 de Ag. de 2014
I suspect you just need something like
eval( current_var )
but I never use eval so I'm not 100% sure that is the correct syntax. Someone else will no doubt answer more confidently on that soon enough!

Michael Haderlein
Michael Haderlein el 18 de Ag. de 2014
Editada: Michael Haderlein el 18 de Ag. de 2014
var_name = ['VAR1, VAR2, VAR3, VAR4'];
I think you rather want it as a cell:
var_name = {'VAR1', 'VAR2', 'VAR3', 'VAR4'};
and then title with
title([num2str(count_2) 'ns: ' ', var_name{count_1} '.....'])

Community Treasure Hunt

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

Start Hunting!

Translated by