Effacer les filtres
Effacer les filtres

How to plot graphs with looping through string variables?

1 vue (au cours des 30 derniers jours)
Chang seok Ma
Chang seok Ma le 25 Août 2021
Commenté : Chang seok Ma le 3 Sep 2021
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

Réponse acceptée

Dave B
Dave B le 26 Août 2021
Modifié(e) : Dave B le 26 Août 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by