function [A1, A2,..............., Am ]=Level[A,m]

조회 수: 3 (최근 30일)
FERNANDO XAVIER ALBAN LEON
FERNANDO XAVIER ALBAN LEON 2018년 8월 17일
댓글: Stephen23 2018년 8월 17일
how do I declare the outputs of a function that has as outputs different size arrays and whose input is the main array and the number of output arrays as follows:
  댓글 수: 1
Stephen23
Stephen23 2018년 8월 17일
Perhaps varargout does what you want. Although this is unlikely to be a good design decision.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2018년 8월 17일
You don't do that (or else you will earn the wrath of Stephen). Not sure why many beginners want to do that. I guess they just aren't thinking ahead.
You return one variable that is a cell array that has a variable number of cells, not a variable number of uniquely-named variables:
function cellArrayA = Level(A,m)
and use parentheses rather than square brackets.
On the other hand, there are functions that return variable numbers of outputs but (I think) that they generally return them all, not a variable number of them. Then it's up to the calling routine to accept the ones you want. For example, the max() function:
maxValue = max(data); % Accepts 1 output value.
[maxValue, indexOfMax] = max(data) ; % Accepts two output values.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by