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!