Why do I receive Arrays have incompatible sizes for this operation
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 22 May 2022
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 Comments
See Also
Categories
Find more on Data Type Conversion 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!