Why do I receive Arrays have incompatible sizes for this operation
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to write an if statement, to prevent the array Index in position 1 exceeding the array bounds, this is the code I have but I recieve an error message as seen below.
Level_Either_Side = [];
for p = 1:length(Componentry_New);
if length(Componentry_New) < Position(1,p)+5
Level_Either_Side == [Level_Either_Side Sorted_Level(Position(1,p)-5:Position(1,p),1)];
elseif Level_Either_Side == [Level_Either_Side Sorted_Level(Position(1,p)-5:Position(1,p)+5,1)];
end
end
This is the error message I recieve.
Error using ==
Arrays have incompatible sizes for this operation.
I was using this code prevously and didn't recieve the above error message:
Level_Either_Side = [];
for p = 1:length(Componentry_New);
Level_Either_Side = [Level_Either_Side Sorted_Level(Position(1,p)-5:Position(1,p)+5,1)];
end
Does anybody know where the eror in the code is, Thank you in advance.
댓글 수: 0
답변 (1개)
Walter Roberson
2022년 5월 22일
You have an if that is then followed by a comparison not by an assignment.
Level_Either_Side == [Level_Either_Side Sorted_Level(Position(1,p)-5:Position(1,p),1)];
The right hand side of that includes Level_Either_Side and 6 additional items. The left hand side of that includes Level_Either_Side . No matter what size Level_Either_Side is, the expression is size N on one side, and N+6 on the other side, and that can never match.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!