Input argument error length of variables
7 次查看(过去 30 天)
显示 更早的评论
I am trying to use the following script to process some of my data. I keep getting this error:
Error using nargin
You can only call nargin/nargout from within a MATLAB function.
function [corrected, details] = pin(year,d13c,alpha,varargin)
↑
Error: Function definitions are not permitted in this context.
] This code was written in 2009 so I don't know if it is outdated or what is going on. I need this to work so any help would be greatly appriciated!
2 个评论
Massimo Zanetti
2016-10-4
You should upload your code otherwise how can we solve your problem? We cannot guess.......
Geoff Hayes
2016-10-4
Elizabeth - the second error message suggests that you have some code that precedes the function definition/signature. If you are defining a function, then it must be the first line in your file.
回答(1 个)
Marc Jakobi
2016-10-7
编辑:Marc Jakobi
2016-10-7
The problem is exactly what the error message says:
Somewhere in your script is the keyword "nargin". nargin is used to check the amount of inputs of a function and because of that it can only be used within a function, not within a script.
Example:
function numinputs = checkinputs(a, b, c)
if nargin == 1
numinputs = 1; %a
elseif nargin == 2
numinputs = 2; %a and b
else
numinputs = 3; %a, b and c
end
end
5 个评论
Walter Roberson
2016-10-9
All of the code starting from 'function' should be stored in pin.m . You can then call upon pin from the command line or from a script. You cannot paste the code in at the command prompt.
If you are using any version before R2016b then it is not permitted to store a function after a script in the same file.
If you are using the new R2016b then it is permitted to store a function after a script in the same file. In such a case the .m file name must not be the name of any function that is stored in the .m file.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Power Converters 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!