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 CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by