this is a part of my code, I am getting this message. "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."

1 view (last 30 days)
ya2 = k(1)*xa2+d(1);
yb2 = k(2)*xb2+d(2);
yc2 = k(3)*xc2+d(3);
for i=1:4
if x2(1)<Vrd_il(i) && x2(2)>Vrd_il(i)
index(i) = find(abs(xa2-Vrd_il(i)) < 0.001);
Y_point(i) = ya2(index(i));
AY_L(i) = min(Y_point(i));
elseif x2(2)<Vrd_il(i) && x2(3)>Vrd_il(i)
index(i) = find(abs(xb2-Vrd_il(i)) < 0.001);
Y_point(i) = yb2(index(i));
AY_L(i) = min(Y_point(i));
elseif x2(3)<Vrd_il(i) && x2(3)>Vrd_il(i)
index(i) = find(abs(xc2-Vrd_il(i)) < 0.001);
Y_point(i) = yc2(index(i));
AY_L(i) = min(Y_point(i));
elseif x2(1)>Vrd_il(i)
AY_L(i) = 0;
AY_L(i) = 0;

Accepted Answer

DGM on 20 Jun 2022
Edited: DGM on 20 Jun 2022
I'm going to go out on a limb and say that there's no reason to believe that the RHS of this assignment is a scalar.
index(i) = find(abs(xa2-Vrd_il(i)) < 0.001);
if it's not a scalar, then the RHS of this assignment won't be scalar either.
Y_point(i) = ya2(index(i));
The same applies for the other cases.
if you intend to retrieve only the first or last index using find(), you can use the 'first' or 'last' option; otherwise, you'll have to find some other way to deal with the fact that there may be more than one result.
That said, I'm only guessing, since I don't know what any of these variables are or where the error actually occurred. If the above is not the case, then you'll have to reveal the actual complete error message.

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!