Random numbers and Matrix

4 views (last 30 days)
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 Comment
Azzi Abdelmalek
Azzi Abdelmalek on 5 Sep 2016
how to make 0 and 1 matrix become 0's one by one. What does that mean?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 5 Sep 2016
Edited: Walter Roberson on 6 Sep 2016
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 Comments
Ahmad Al-jelali
Ahmad Al-jelali on 6 Sep 2016
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 on 6 Sep 2016
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...)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!