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 (최근 30일)
xa2=linspace(x2(1),x2(2),1000);
ya2 = k(1)*xa2+d(1);
xb2=linspace(x2(2),x2(3),1000);
yb2 = k(2)*xb2+d(2);
xc2=linspace(x2(3),x2(4),1000);
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;
else
AY_L(i) = 0;
end
end

채택된 답변

DGM
DGM 2022년 6월 20일
편집: DGM 2022년 6월 20일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by