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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by