필터 지우기
필터 지우기

Passing Function results to another function

조회 수: 4 (최근 30일)
Michael
Michael 2013년 1월 23일
I recently ran into some behavior I though was unintuitive - given the code below, nargin prints out 1. Why isn't the second argument being passed to test2? Is there a standard way to get around this issue?
test2(test())
1
function [a,b] = test( )
a=5;
b=6;
end
function test2( a,b)
nargin
end

채택된 답변

Matt J
Matt J 2013년 1월 23일
편집: Matt J 2013년 1월 23일
Multiple output arguments must be explicitly requested and assigned:
[A,B]=test;
test2(A,B)
or
[AB{1:2}]=test;
test2(AB{:}),
  댓글 수: 2
Matt J
Matt J 2013년 1월 23일
or you could return your arguments in a vector
function ab = test( )
ab=[5,6]
end
function test2( ab)
numel(ab)
end
Walter Roberson
Walter Roberson 2013년 1월 23일
Right. This is a design feature of MATLAB, that when it sees that the result of a function is being passed to another function, all but the first output is discarded. This is fairly tricky to get around (I did see someone find a way once using deal() but I'm not convinced it would work.)

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by