Info

この質問は閉じられています。 編集または回答するには再度開いてください。

multiple selections from an iteration

1 回表示 (過去 30 日間)
summyia qamar
summyia qamar 2016 年 12 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I'm running this code.
part_machine=[1 0 0 1 0 1 1
0 1 1 1 0 0 1
1 0 0 1 1 0 0
1 0 0 0 1 0 1
1 1 0 0 0 1 0
0 1 0 0 0 1 1];
demand=[600;550;620;500;590;600];
numIterations=100;
for k=1:numIterations
rand_cell=randi([0,1],7,3);
if all(sum(rand_cell,2)==1);
Part_cell(k)=part_machine*rand_cell;
end
Part_cell(Part_cell>=1)=1
no_of_movements=sum(Part_cell,2)-1;
movement_cost(k)=sum(bsxfun(@times,no_of_movements,demand));
end
minval=min(movement_cost);
[rand_cell minval(ones(7,1))]
the idea behind this code is * generate rand_cell * select that rand_cell in which sum of rows is 1 * multiply Part_machine matrix with that rand_cell * then apply the other functions on part_machine matrix * then at the end select the minval from all iterations * result is displayed with that rand_cell matrix which has generated the minimum value
now the result I'm getting is like this
ans =
1 0 1 6920
1 0 0 6920
0 1 0 6920
1 1 0 6920
1 1 1 6920
1 1 1 6920
1 0 1 6920
it is not the rand_cell matrix according to condition
all(sum(rand_cell,2)==1)
where is the problem?
  2 件のコメント
José-Luis
José-Luis 2016 年 12 月 19 日
編集済み: José-Luis 2016 年 12 月 19 日
You are not providing all the code necessary to answer this question. What is Part_cell? One could of course browse all your previous questions but it is better (as in easier for us) if your questions were self-contained.
summyia qamar
summyia qamar 2016 年 12 月 19 日
編集済み: summyia qamar 2016 年 12 月 19 日
I mean that part_cell is generated as
part_machine* rand_cell)
where rand_cell should satisfy
all(sum(rand_cell,2)==1)

回答 (1 件)

Jan
Jan 2016 年 12 月 19 日
After
rand_cell = randi([0,1],7,3);
the condition
if all(sum(rand_cell,2)==1)
Part_cell(k)=part_machine*rand_cell;
end
is very unlikely. The body of this IF-Block is most likely not entered.
But if it is satisfied
no_of_movements = sum(Part_cell, 2) - 1
replies zeros only.
To get a random matrix with one 1 per row:
index = randi([1,3], 1, 7);
Part_cell = zeros(7, 3);
Part_cell(sub2ind([7,3], 1:7, index)) = 1;
  2 件のコメント
summyia qamar
summyia qamar 2016 年 12 月 19 日
now the result of all iterations is same value
Jan
Jan 2016 年 12 月 20 日
Then please the relevant part of the code which reproduces the problem.

この質問は閉じられています。

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by