Creating small elevator code

조회 수: 15 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by