Borrar filtros
Borrar filtros

How to plot graphs with looping through string variables?

1 visualización (últimos 30 días)
Chang seok Ma
Chang seok Ma el 25 de Ag. de 2021
Comentada: Chang seok Ma el 3 de Sept. de 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

Respuesta aceptada

Dave B
Dave B el 26 de Ag. de 2021
Editada: Dave B el 26 de Ag. de 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

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by