How to use multiple outputs from function

14 Ansichten (letzte 30 Tage)
Etan Cole
Etan Cole am 18 Nov. 2014
Kommentiert: Matt J am 18 Nov. 2014
function[x,y]=rowcolum(a,b)
x=max(sum(a,2));
y=min(sum(b,1));
end
how to write a code that will sum x+y in main script?

Akzeptierte Antwort

Thorsten
Thorsten am 18 Nov. 2014
Why not
z = x + y;
  3 Kommentare
Matt J
Matt J am 18 Nov. 2014
Bearbeitet: Matt J am 18 Nov. 2014
But why not simply invoke the function, obtain 2 outputs, and then sum them:
[x,y]=rowcolumn(a,b); %a call to rowcolumn
z=x+y
Etan Cole
Etan Cole am 18 Nov. 2014
that was what i wanted thanks man :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt J
Matt J am 18 Nov. 2014
Bearbeitet: Matt J am 18 Nov. 2014
I assume you want to do the summation outside the workspace, for some reason . If so, then,
outputsRequested=2;
[c{1:outputsRequested}]=rowcolumn(a,b);
result = sum([c{:}])
  2 Kommentare
Etan Cole
Etan Cole am 18 Nov. 2014
i want the two outputs and use them seperately. when i call the function in my workspace appears only x and y is no where to be found
Matt J
Matt J am 18 Nov. 2014
You can later assign the output to separate variables if you wish,
x=c{1}
y=c{2}
but why you wouldn't simply use c{1} and c{2} instead of separate variables x and y is not clear.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by