Indexing error in loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have this cell array
Selected_route=
Column 1
[1x7 double]
Column 2
[1x7 double]
Column 3
[1x7 double]
Column 4
[1x7 double]
Column 5
[1x7 double]
Column 6
[1x7 double]
I want to check each value of individual a [1x7] array over a condition that
Selected_route{x}(y)(Selected_route{x}(y)>=1)=1
my complete code fro the problem is
Total_Products=6;
Types_Machine=7
for x=1:Total_Products
for y=1:Types_Machine
Movement=0;
Movement=Movement+(Selected_Routes{x}(y)(Selected_Routes{x}(y)>=1)=1)
end
end
Total_movement(x)=Movement
end
I want to do that Movement value is increased every time if the condition is met.. the error received is cannot call or index into a temporary array and I want that the
output Total_movement=[sum of all values in array 1] [sum of all values in array 2] upto Types_products number of arrays
0 comentarios
Respuestas (1)
Walter Roberson
el 5 de En. de 2017
"=" is an assignment in MATLAB. Your code
Movement=Movement+(Selected_Routes{x}(y)(Selected_Routes{x}(y)>=1)=1)
attempts to have two assignments in the same expression.
The MATLAB equality comparison operator is "=="
2 comentarios
Walter Roberson
el 5 de En. de 2017
Remove the for y loop. Use
Movement = sum(Selected_Routes{x}>=1);
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!