MATLAB Answers

I dont understand this error

2 views (last 30 days)
David David
David David on 18 Sep 2021
Commented: Image Analyst on 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".

Answers (1)

Image Analyst
Image Analyst on 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 Comment
Image Analyst
Image Analyst on 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).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by