TVP - VAR Package Nakajima (2011)

44 次查看(过去 30 天)
Hi,
I used Nakajima's code but I get an error when plotting impulse response functions. Can someone who works with the code help me? or help me solve it?
The exact error is : Index in position 2 exceeds array bounds.
Psdt.
I do not modify the code.
function [] = drawimp(vt, fldraw)
global m_ns m_nk m_nl m_asvar;
ns = m_ns;
nk = m_nk;
nl = m_nl;
mimpr = xlsread('tvpvar_imp.xlsx');
mimpm = mimpr(:, 3:end);
nimp = size(mimpm, 1) / m_ns;
mline = [0 .5 0; 0 0 1; 1 0 0; 0 .7 .7];
vline = {':', '--', '-', '-.'};
nline = size(vt, 2);
figure
for i = 1 : nk
for j = 1 : nk
id = (i-1)*nk + j;
mimp = reshape(mimpm(:, id), nimp, ns)'; %% Here the error
subplot(nk, nk, id);
if fldraw == 1
for k = 1 : nline
plot(mimp(:, vt(k)+1), char(vline(k)), ...
'Color', mline(k, :))
hold on
end
vax = axis;
axis([nl+1 ns+1 vax(3:4)])
if vax(3) * vax(4) < 0
line([nl+1, ns+1], [0, 0], 'Color', ones(1,3)*0.6)
end
if id == 1
vlege = ['-period ahead'];
for l = 2 : nline
vlege = [vlege; '-period '];
end
legend([num2str(vt') vlege])
end
else
for k = 1 : nline
plot(0:nimp-1, mimp(vt(k), :), char(vline(k)), ...
'Color', mline(k, :))
hold on
end
vax = axis;
axis([0 nimp-1 vax(3:4)])
if vax(3) * vax(4) < 0
line([0, nimp-1], [0, 0], 'Color', ones(1,3)*0.6)
end
if id == 1
vlege = ['t='];
for l = 2 : nline
vlege = [vlege; 't='];
end
legend([vlege num2str(vt')])
end
end
hold off
title(['$\varepsilon_{', char(m_asvar(i)), ...
'}\uparrow\ \rightarrow\ ', ...
char(m_asvar(j)), '$'], 'interpreter', 'latex')
end
end

回答(1 个)

Tomas Oles
Tomas Oles 2021-7-31
编辑:Tomas Oles 2021-7-31
Hi Anthony, I have faced the same problem, try this solution:
  1. go to function drawimp(vt, f1)
  2. in the line 6, where you read data for IRF fuction in commad mimpr = xlsread('tvpvar_imp.xlsx'), specify the Sheet1 (like this:mimpr = xlsread('tvpvar_imp.xlsx', 'Sheet1'))your data are in. Probably you have some sheet in your Excel (in some other language) before the data to IRF are, and the Matlab loads the empty table.
Hope it help, Tomas.

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by