Random numbers and Matrix

2 ビュー (過去 30 日間)
Ahmad Al-jelali
Ahmad Al-jelali 2016 年 9 月 5 日
コメント済み: Walter Roberson 2016 年 9 月 6 日
a=30;
b=3;
A=rand(a,b)<0.85;
B=zeros(30,1);
C=A;
D=[A B C]
This is what I am using now and would like to know how to make 0 and 1 matrix become 0's one by one. I am making a aircraft model and I am using 30*7 matrix to simulate people getting off the plane. Any suggests how to go about doing this?
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 9 月 5 日
how to make 0 and 1 matrix become 0's one by one. What does that mean?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 9 月 5 日
編集済み: Walter Roberson 2016 年 9 月 6 日
Example:
col_order = [3 5 2 6 1 7];
seat_letters = 'ABCxDEF';
for K = 1 : length(col_order)
this_col = col_order(K);
left_in_col = reshape( find(D(:,this_col)), 1, []);
for row = left_in_col
D(row, this_col) = 0;
fprintf('Passenger in %d%c got off\n', row, seat_letters(this_col));
end
end
  2 件のコメント
Ahmad Al-jelali
Ahmad Al-jelali 2016 年 9 月 6 日
Thanks, Walter your are a legend but what would I need to change in the code if I want to deplane using Front and Back exit to speed up the deplaning of the aircraft. Your help is very highly appreciated and regarded.
Walter Roberson
Walter Roberson 2016 年 9 月 6 日
The number and location of the exits is irrelevant, as you are teleporting the passengers and their luggage off of the plane one at a time, rather than considering their motion between the time they stand up and the time they are off of the plane, or the fact that passengers queue up to leave the plane.
If you want to have an output that looks something like,
Passenger in 3C got left by the front exit and passenger in 27D left by the rear exit
then you need to adapt the code to make decide two seats at a time. When you do so you need to make decisions about which exit will be used. When you do that you need to take into account the possibility that there might be an odd number of passengers in any one column (seat letter).
You also need to take into account that because passengers are not evenly distributed that it could be the case that your algorithm might end up suggesting that 26D leave through the front exit while 27D is leaving through the rear exit even though the rear exit is much closer for 26D, and you would get a net slowdown if you had to wait for 26D to walk the extra distance before you were to allow another passenger to stand up. (But how much of a net slowdown? You need to work that out, considering that passengers typically walk faster along an open isle than they are able to exit through a "pinch-point" that is a plane door, especially if there are stairs to be navigated. Passengers have to slow at each turn...)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by