Why do I receive Arrays have incompatible sizes for this operation

1 visualización (últimos 30 días)
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de Mayo de 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.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by