varargout,可以看做“Variable length output argument list”的縮寫。
基本簡介,相關例子,調用及輸出,
基本簡介
matlab中varargout簡介
varargout可以看做“Variable length output argument list”的縮寫。在matlab中定義m函式時通過varargout我們可以得到可變個數個返回值。在matlab命令視窗中輸入doc varargout或help varargout可以獲得相關幫助信息。
相關例子
下面我們來看一個簡單的例子
function varargout = foo(varargin)
for k=1:nargout
varargout(k) = varargin(k); % the same as {varargin{k}};
end
disp(' ');
end
調用及輸出
>> ret = foo(1, 2, 3);
How many output arguments? 1
And they are:
1
>> [retA, retB] = foo(1, 2, 3);
How many output arguments? 2
And they are:
1 2
>> [retA, retB, retC] = foo(1, 2, 3);
How many output arguments? 3
And they are:
1 2 3