Not enough input arguments(if isinteger(x))

Dear everyone!
I am comparing two models and I get the following error:
Not enough input arguments.
Error in var (line 73)
if isinteger(x)
Error in compa_4 (line 21)
for jj=1:length(var)
My code is:
dynare thesimy.mod;
irf1 = oo_.irfs;
save thesimy.mat irf1;
dynare thesimy2.mod;
irf2 = oo_.irfs;
save thesimy2.mat irf2;
load('thesimy.mat','irf1');
load('thesimy2.mat','irf2');
ending_cell={'_eps_a','_eps_r','_eps_g','_eps_tau'};
%'Hiato do produto', 'Inflação Doméstico', 'Consumo Doméstico',
%'PIB','Inflação IP','Termo de Troca', 'Salário Real', 'Horas de
%Trabalho','Dívida','Câmbio Nominal','Balanço Comercial','Taxa de Juros Real'
for ii=1:length(ending_cell)
HOR=1:options_.irf;
var_titles = {'Hiato do produto', 'Inflação Doméstico', 'Consumo Doméstico', 'PIB', 'Inflação IPC', 'Termo de Troca', 'Salário Real', 'Horas de Trabalho','Dívida', 'Câmbio Nominal','Balanço Comercial','Taxa de Juros Real'};
figure
for jj=1:length(var)
subplot(4,4,jj)
eval(['irf1.' var{1,jj},ending_cell{1,ii}]);
eval(['irf2.' var{1,jj},ending_cell{1,ii}]);
hold on
plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'–r','LineWidth',2);
title([var_titles{1,jj}] )
end
legend('Modelo com HP', 'Modelo com TC', 'AutoUpdate','off')
end
Thank you for helping to resolve the issue.

3 个评论

Rather than this complex and inefficient code:
eval(['irf1.' var{1,jj},ending_cell{1,ii}])
you can easily use this simpler and much more efficient code:
irf1.([var{1,jj},ending_cell{1,ii}])
The dynare documentation shows a very unfortunate reliance on command syntax, apparently magically throws lots of variables between workspaces, the documentation shows changing the current directory to access the data files, and the documentation even admits that it calls CLEAR ALL internally when it is run! 😢
Thanks you very much,
I tried irf1.([var{1,jj},ending_cell{1,ii}]) but is giving the same problem.
"Thanks you very much, I tried ... but is giving the same problem."
My comment above does not fix your problem (nor did I write that it will fix your problem).
My comment above shows you how to write simpler, more efficient code (which is exactly what I wrote):
Rather than this complex and inefficient code:
eval(['irf1.' var{1,jj},ending_cell{1,ii}])
you can easily use this simpler and much more efficient code:
irf1.([var{1,jj},ending_cell{1,ii}])

请先登录,再进行评论。

 采纳的回答

Is var expected to be a variable? If so, then it's not defined. It's helpful to avoid naming variables in a way that overloads existing function names. This is relevant because var() is a function. You're calling var() without any arguments.
help var
Also: formatting your code with the post editor helps make it readable.

8 个评论

Most likely var is intended to be loaded magically directly into the workspace, but this approach is latent buggy: the JIT parser already knows about the function, which easily leads to unexpected bugs and errors, a topic which has already been discussed many times in detail:
Thanks you very much,
Var is a function and var_titles is a variable.
When I put some variables (a small number of variables, 5 variables for example) in var_titles (1, 2, ....5), the model executes normally without any problem. But when I put a lot of variables (12 variables for example ) in var_titles(1, 2, 3 ....12), the model shows the above problem.
@Touré Mohamed: your code is buggy. You can write much more robust code by following the information at the link I gave above: did you read any of it? In particular, you should always load into an output variable (which is a scalar structure) and access its fieldnames:
S = load(...);
S.whatever
Do not use eval to access fieldnames, unless you want to continue wasting time trying to fix pointless bugs.
This will take you a looooong way on fixing that bug and making your code much more robust.
Note that dynare does not use good code practices, do NOT learn from its examples or functions (the MATLAB documentation and this forum are much better).
The problem is with the line:
for jj=1:length(var)
What is supposed to happen when you try to run something like length(var)? If var is a user-defined function with no arguments, then you might get an answer. If var() expects arguments and receives none, then it will throw an error the moment it tries to use said arguments.
I know you said that var() is a function, but this:
var{1,jj}
suggests that you expect var to be a cell array instead, so which is it? Regardless of what you expect var to be, var in this case is a function -- specifically, it appears var() is the built-in function for variance, not any user-defined function or variable by the same name. A simple test replicates the error.
% ensure there are no user-defined variables or functions called var
clear all
for jj=1:length(var)
fprintf('this won''t run')
end
Since nowhere in this code is var defined as either a variable or a function, then I can only guess where it's supposed to come from or the conditions which cause it to exist.
EDIT: I didn't see Stephen's answer which is probably the answer to the "where it's supposed to come from" part.
Thank you Stephen and DGM.
Dear Stephen I read it, but it a little hard to understand. I am new to Matlab. Do you have any sample code that might make it easier for me to understand, please?
Thanks a lot,
@Touré Mohamed: some ways of writing code are more robust (i.e. less liable to bugs) than other ways.
The way that you have chosen to import the file data is liable to bugs, exactly like the one you are getting (where it is not clear to any reader nor MATLAB if var is a function or a variable loaded from a mat file).
The best way to fix this bug is to write more robust code, e.g. loading into an output variable:
S = load(...)
S is a scalar structure. You can access all of the loaded data as fields of that structure, e.g. if the mat file contains a variable (badly) named var, then you can access it like this:
S.var
Get rid of those eval calls: you do no need them and they just make your code more complex and difficult to debug.
I tried to do what you suggested. But my model is not working.
I received the following error:
Error using copyfile
Cannot write to destination: C:\Users\abdel\Documents. Use the 'f' option to override.
Error in testcom (line 12)
copyfile('S1.mat','S3.mat')
Please take a look at what I did.
dynare thesimyp1.mod;
irf1 = oo_.irfs;
S1 = 'thesimyp1';
save S1.mat S1
dynare thesimyp2.mod;
irf2 = oo_.irfs;
S2 = 'thesimyp2';
save S2.mat S2
copyfile('S1.mat','S3.mat')
S = load('S2.mat');
save('S3.mat','-struct','S','-append')
ending_cell={'_eps_a','_eps_r','_eps_g','_eps_tau'};
%'Hiato do produto', 'Inflação Doméstico', 'Consumo Doméstico',
%'PIB','Inflação IP','Termo de Troca', 'Salário Real', 'Horas de
%Trabalho','Dívida','Câmbio Nominal','Balanço Comercial','Taxa de Juros Real'
for ii=1:length(ending_cell)
HOR=1:options_.irf;
var_titles = {'Hiato do produto', 'Inflação Doméstico', 'Consumo Doméstico', 'PIB', 'Inflação IPC', 'Termo de Troca', 'Salário Real', 'Horas de Trabalho','Dívida', 'Câmbio Nominal','Balanço Comercial','Taxa de Juros Real'};
figure
for jj=1:length(S)
subplot(3,3,jj)
irf1.([S{1,jj},ending_cell{1,ii}]);
irf2.([S{1,jj},ending_cell{1,ii}]);
hold on
plot(HOR,[(['irf1.' S{1,jj},ending_cell{1,ii}])],'-k',HOR,[(['irf2.' S{1,jj},ending_cell{1,ii}])],'--r','LineWidth',2);
title([var_titles{1,jj}])
end
legend('Modelo com HP', 'Modelo com TC', 'AutoUpdate','off')
end
Best regard,
I suspect that S3.mat already exists but you cannot write to it. Possibly it is open in another program.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Use Prebuilt MATLAB Interface to C/C++ Library 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by