error associated with Nargin
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I download Matlab code and it worked well in an old version of Matlab. However, when I run it in Matlab R2017b I get an error message related to nargin. It says, you can only call nargin/narginout from within MatLab function.
1 comentario
Image Analyst
el 24 de En. de 2018
OK. Do you have a question? You've included neither the error message nor the code, so what can we say?
Respuestas (2)
Rik
el 24 de En. de 2018
I just tested to confirm. For some odd reason you could use the nargin function in a script m-file. This returned the value for the calling function. The solution is to actually use the nargin function in a context it makes sense: a function.
Move calls to nargin, nargout, and inputname into the relevant function file. If you need the results in a script, call the functions and store the results in a variable. Then use the variable in the script.
0 comentarios
Walter Roberson
el 24 de En. de 2018
This was a change as of R2016b. Before that, if you called nargin from inside a script it would not error but would return 0; as of R2016b it errors.
There was never a great reason to call nargin from inside a script; about the only use for it was that if you temporarily commented out a function line so that variables would not disappear when the function exited, then you did not have to change nargin references.
You should either add a function header to the code to convert it to a function (in which nargin is a meaningful thing to query), or else you should replace the nargin with 0 (and potentially clean up the code afterwards.)
2 comentarios
Rik
el 24 de En. de 2018
When I tested it, I got seemingly random numbers. For example, calling a file with only disp(nargin) inside it results in 123863040 (win10x64, R2012b). In 6.5 it results in -2.1475e+009.
But to be fair, I called the file directly, not from inside another function.
Walter Roberson
el 24 de En. de 2018
Hmmm, not much pattern on OS-X version
- R2010bSP1 -> 1
- R2011a -> 32767 (0x7FFF)
- R2011b -> 32767 (0x7FFF)
- R2012a -> -483851947 (0xE3290155)
- R2012b -> 28672 (0x7000)
- R2013a -> 28672 (0x7000)
- R2013b -> 0
- R2014a -> 32711 (0x7FC7)
- R2014b -> 28672 (0x7000)
- R2015aSP1 -> 32640 (0x7F80)
- R2015b -> errors already even though release notes for R2016a say it should still run
- R2016a -> errors already even though release notes for R2016a say it should still run
Ver también
Categorías
Más información sobre Entering Commands en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!