Indexing error in loop
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Walter Roberson
2017 年 1 月 5 日
"=" 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 件のコメント
Walter Roberson
2017 年 1 月 5 日
Remove the for y loop. Use
Movement = sum(Selected_Routes{x}>=1);
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!