Using values from an array as titles in generated figures
조회 수: 16 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
Michael Haderlein
2014년 8월 18일
편집: Michael Haderlein
2014년 8월 18일
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} '.....'])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!