I dont understand this error

1 Ansicht (letzte 30 Tage)
David David
David David am 18 Sep. 2021
Kommentiert: Image Analyst am 18 Sep. 2021
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".

Antworten (1)

Image Analyst
Image Analyst am 18 Sep. 2021
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 Kommentar
Image Analyst
Image Analyst am 18 Sep. 2021
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).

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by