Indexing error in loop

조회 수: 1 (최근 30일)
summyia qamar
summyia qamar 2017년 1월 5일
댓글: Walter Roberson 2017년 1월 5일
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

답변 (1개)

Walter Roberson
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
summyia qamar
summyia qamar 2017년 1월 5일
but doing this
Movement=Movement+(Selected_Routes{x}(y)(Selected_Routes{x}(y)>==1)=1)
but still parse error is given
Walter Roberson
Walter Roberson 2017년 1월 5일
Remove the for y loop. Use
Movement = sum(Selected_Routes{x}>=1);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by