Effacer les filtres
Effacer les filtres

Input argument error length of variables

7 vues (au cours des 30 derniers jours)
Elizabeth Olson
Elizabeth Olson le 4 Oct 2016
Commenté : Marc Jakobi le 9 Oct 2016
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 commentaires
Massimo Zanetti
Massimo Zanetti le 4 Oct 2016
You should upload your code otherwise how can we solve your problem? We cannot guess.......
Geoff Hayes
Geoff Hayes le 4 Oct 2016
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.

Connectez-vous pour commenter.

Réponses (1)

Marc Jakobi
Marc Jakobi le 7 Oct 2016
Modifié(e) : Marc Jakobi le 7 Oct 2016
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 commentaires
Walter Roberson
Walter Roberson le 9 Oct 2016
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.
Marc Jakobi
Marc Jakobi le 9 Oct 2016
Nice, I was not aware of that new feature.

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by