Variable number of output arguments

5 ビュー (過去 30 日間)
James
James 2015 年 2 月 17 日
コメント済み: James 2015 年 2 月 17 日
Hi everyone,
I am wondering how I can dynamically change the number of returned arguments I want to receive from a function. Example:
function foo()
a = fooyootoo(3)
end
function varargout = fooyootoo(n)
for i = 1:n
varargout{i}=i;
end
end
I would like to define 'a' so that it is a cell array with a dynamic number of cells between 1 and n. Note, I do not want to execute the function fooyootoo() more than once.
Thanks,
James

採用された回答

Jan
Jan 2015 年 2 月 17 日
編集済み: Jan 2015 年 2 月 17 日
function foo()
n = 3;
[a{1:n}] = fooyootoo(n);
end
It would be easier to reply a cell directly.
  1 件のコメント
James
James 2015 年 2 月 17 日
Thanks Jan,
So simple... :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by