I dont understand this error

조회 수: 1 (최근 30일)
David David
David David 2021년 9월 18일
댓글: Image Analyst 2021년 9월 18일
e =rand(1,100);
T = rand(1,100);
[A,B] = pair(e,T);
plot(A(1),A(2))
plot(B(1),B(2))
function [A,B] = pair(C,D)
if (C > 0.3) & (D < 0.3)
A = [C,D];
else
B = [C,D];
end
end
I dont understand this error
Output argument "A" (and maybe others) not assigned during call to "pairwise".

답변 (1개)

Image Analyst
Image Analyst 2021년 9월 18일
You need to assign BOTH A and B, not just one of them. You only went into the else block and so you only assigned B, not A. So you can do
function [A,B] = pair(C,D)
A = 0; % or null []
B = 0;
if (C > 0.3) & (D < 0.3)
A = [C,D];
else
B = [C,D];
end
or just have one output
function result = pair(C,D)
if (C > 0.3) & (D < 0.3)
result = [C,D];
else
result = [C,D];
end
  댓글 수: 1
Image Analyst
Image Analyst 2021년 9월 18일
Also, your error mentioned pairwise, which you didn't give. You only gave us the pair() function, not pairwise(), but essentially the concept/fix would be the same. You always have to assign all output variables (unless you do special tricks).

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

카테고리

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