필터 지우기
필터 지우기

How to plot graphs with looping through string variables?

조회 수: 1 (최근 30일)
Chang seok Ma
Chang seok Ma 2021년 8월 25일
댓글: Chang seok Ma 2021년 9월 3일
Hello,
I have one question about plotting graphs.
I want to use loop with string variables as below.
Basically, I want to read the sheet of the excel and also put the title of the graph using string variables.
But with the code I wrote as below, I am using 'specification' which is a number not a string.
Is there any way I can deal with this?
Thank you.
group = {'r_new_car' 'r_used_car' 'r_used_truck'};
for member = 1:length(group)
specification = member;
figcount = 1;
horizon = xlsread('results.xlsx',specification,'C2:K2');
coefficients = xlsread('results.xlsx',specification,'C4:K4');
ses = xlsread('results.xlsx',specification,'C5:K5');
h_to_plot = linspace(1,9,9);
%,'LineSpec','-'
errorbar(horizon(h_to_plot),coefficients(h_to_plot),quant*ses(h_to_plot),'o','Linewidth',1.5)
line([-4,7],[0,0],'Color',black,'LineStyle','-')
xlim([-4 6])
grid on
xticks(-3:1:5)
title(specification)
set(figure(figcount), 'PaperUnits', 'inches');
scale = 3;
x_width=scale*3; y_width=scale*2;
set(figure(figcount), 'PaperPosition', [0 0 x_width y_width]);
%print(strcat('result','_',specification),'-dpng','-r300')
figcount = figcount + 1;
hold off
end

채택된 답변

Dave B
Dave B 2021년 8월 26일
편집: Dave B 2021년 8월 26일
I agree with @Stephen, your life will be much easier if you use readtable.
Are you saying you want to use specification and find the corresponding values in group?
group = {'r_new_car' 'r_used_car' 'r_used_truck'};
for member = 1:length(group)
specification = member; % not sure what this line does, you could just use write specification above instead of member
groupname = group{specification};
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by