Varargin - mistake in my example

1 Ansicht (letzte 30 Tage)
Gennaro Arguzzi
Gennaro Arguzzi am 13 Mai 2017
Beantwortet: Andrei Bobrov am 13 Mai 2017
Hi everyone, I wrote the following function:
function [x] = ingressi_arbitrari(varargin)
x=0;
for k=1:nargin
x=x+1;
end
end
Why if I run a=ingressi_arbitrari([2 3]) in the command window, the result is a=1 instead of a=2 (I choose two input arguments)?
Thank you very much.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Mai 2017
You only have one input argument, that happens to be length 2. If you had
a=ingressi_arbitrari([2 3], [7; 1; 8; 5])
then you would have two input arguments, the first length 2 and the second length 4

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 13 Mai 2017
use:
ingressi_arbitrari(2,3)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by