Combining plots for IRFs with Matlab

Hi prof,
I have tried to combine IRFs from two excel files for 15 subplots; As I intended to ignore colum 14th, hence I applied to the “i=1,length” loops function, I have tried the code as below:

load IRF1.csv;
print=[1,2,3,4,5,6,7,8,9,10,11,12,13,15,16];
varname=strvcat('r','inv','qq','k','infl','w',...
'c','y','lab','mpk','s','rk','n','m0','m2'); 

for i=1:length(print)
subplot(3,5,i)
la=plot(IRF1(:,i),'r--')
la.LineWidth=1;
title(varname(i,:));
end;

hold on;

load IRF.csv;
print1=[1,2,3,4,5,6,7,8,9,10,11,12,13,15,16];

for i=1:length(print1)
subplot(3,5,i)
la=plot(IRF(:,i))
la.LineWidth=1;
xlabel('Time period')
ylabel('pp point')


hold off;
end;

However, only the last suplot was successful, please could you help me with the rest 14 subplots? see attached the screenshot and excel files.

IRF.xlsx (14.3 KB)
IRF1.xlsx (14.3 KB)

due to the Forum regulation, I have saved the excel files in xlsx, on my own PC I was working with csv format.

You need one loop as hold commands only apply to the respective subplot. It should be something like

load IRF1.csv;
load IRF.csv;
print=[1,2,3,4,5,6,7,8,9,10,11,12,13,15,16];
varname=strvcat('r','inv','qq','k','infl','w',...
    'c','y','lab','mpk','s','rk','n','m0','m2');

for i=1:length(print)
    subplot(3,5,i)
    la=plot(IRF1(:,i),'r--');
    la.LineWidth=1;
    title(varname(i,:));
    hold on;
    la=plot(IRF(:,i));
    la.LineWidth=1;
    xlabel('Time period')
    ylabel('pp point')
end
1 Like