Indexing error in loop

2 次查看(过去 30 天)
summyia qamar
summyia qamar 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