Creating small elevator code

13 ビュー (過去 30 日間)
Claudia Gurrola
Claudia Gurrola 2016 年 5 月 7 日
コメント済み: Weird Rando 2016 年 5 月 7 日
I created a code for a random amount of people to get into the elevator and an exact same random of floors selected but I am having trouble setting up the ascending part. I tried to do the for/end function to automatically go but it came to an error, can someone help please.
%Elevator
a = nonzeros(round(10*rand(1,1))) %number of people entering
e(1).floor='lobby';
e(2).floor='firstfloor';
e(3).floor='secondfloor';
e(4).floor='thirdfloor';
e(5).floor='fourthfloor';
e(6).floor='fifthfloor';
e(7).floor='sixthfloor';
e(8).floor='seventhfloor';
e(9).floor='eightfloor';
e(10).floor='ninethfloor';
n = round(9*rand(1,a)) %number floor selected
o = n
for o = [1:10]
x(o) = n*1;
end
%%I was going to try this but it seemed more messy
%if(num1>num2)
% disp('num1 goes first')
%elseif (num1>num3)
% disp('num1 goes first')
%elseif (num1>num4)
% disp('num1 goes first')
%elseif (num1>num5)
% disp('num1 goes first')
%elseif (num2>num1)
% disp('num2 goes first')
%elseif (num2>num3)
% disp('num2 goes first')
%elseif (num2>num4)
% disp('num2 goes first')
%elseif (num2>num5)
% disp('num2 goes first')
%elseif (num3>num1)
% disp('num3 goes first')
%elseif (num3>num2)
% disp('num3 goes first')
%elseif (num3>num4)
% disp('num3 goes first')
%elseif (num3>num5)
% disp('num3 goes first')
%elseif (num4>num1)
% disp('num4 goes first')
%elseif (num4>num2)
% disp('num4 goes first')
%elseif (num4>num3)
% disp('num4 goes first')
%elseif (num4>num5)
% disp('num4 goes first')
%elseif (num5>num1)
% disp('num5 goes first')
%elseif (num5>num2)
% disp('num5 goes first')
%elseif (num5>num3)
% disp('num5 goes first')
%elseif (num5>num4)
% disp('num5 goes first')
%else
% disp('no floor is selected')
%end
  1 件のコメント
Weird Rando
Weird Rando 2016 年 5 月 7 日
Problem is you are trying to make an array (1xN) to fit into a single array (1x1). What exactly are you trying to do with this code?
n = round(9*rand(1,a)) %number floor selected

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

回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by