How to loop different y-labels in different plots?

I want to display 4 graphs of Impulse Response Functions (IRFs) with their confidence intervals. I would like the labels to appear in bold on the y-axis. I tried this code but it doesn't display the y-axis as plotdisplay says. Besides, when I run the code, the order of the plots doesn't reflect the order of the variables and one (the last one) isn't displayed.
plotdisplay = {'Fiscal Policy Accommodation', 'HICP', 'Real GDP', 'Policy Indicator'}
for j = 1:4
plot(VAR.irs(:,j),'LineWidth',2,'Color', [0 0 0.5]);
hold on
plot(VARbs.irsH(:,j),'LineWidth',1,'Color', [0 0 0.5],'LineStyle','--');
hold on
plot(VARbs.irsL(:,j),'LineWidth',1,'Color', [0 0 0.5],'LineStyle','--');
subplot(size(VAR.irs, 2), 1, j);
xlabel('months')
ylabel(plotdisplay(j), 'bold')
end
What is wrong in this code?
Thanks

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 3 de Abr. de 2020
Editada: Ameer Hamza el 3 de Abr. de 2020
Change to
ylabel(plotdisplay(j), 'FontWeight', 'bold')
Also move the subplot statement above
for j = 1:4
subplot(size(VAR.irs, 2), 1, j);
plot(VAR.irs(:,j),'LineWidth',2,'Color', [0 0 0.5]);
hold on
% remaining code.
end

6 comentarios

Thanks a lot Ameer! It works fine now!
Ameer Hamza
Ameer Hamza el 3 de Abr. de 2020
Glad to be of help.
Great help. Can I ask you one more question? How do you change in MATLAB the size of the 4 graphs? To shrink the length and increase height for example in the final display?
You can add the following line to change the dimensions of current figure
f = gcf;
f.Position(3) = f.Position(3) + 300; % increase width a little, adjust the value of 300
f.Position(4) = f.Position(4) - 100; % decrease height a little, adjust the value of 100
impressive! Thanks a lot!
Ameer Hamza
Ameer Hamza el 3 de Abr. de 2020
Thanks. Glad to help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 3 de Abr. de 2020

Comentada:

el 3 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by