How to plot graphs with looping through string variables?

1 次查看(过去 30 天)
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