How to plot graphs with looping through string variables?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
1 commentaire
Stephen23
le 25 Août 2021
Probably you should import the file as a table:
then you can just loop over the column/variable names:
Réponse acceptée
Dave B
le 26 Août 2021
Modifié(e) : Dave B
le 26 Août 2021
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)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!