简体   繁体   中英

how do i write 1 to 7 days condition in if statement in matlab?

period=input('Enter the rental period:');
toc=menu('Select type of the car from menu.','Class B','Class C','Class D');
if period>60
   disp('Rental is not available for more than 60 days.')
else if period<7 & toc==3
   disp('Class D cars can not be rented for less than 7 days')
else if period=1<6 & toc==2

i am doing a calculation here and checking some conditions to get the cost of renting car. i am stuck on the last line how do i check whether the period is within 1 to days or not?

Alternate Solution:

You can use the statement B == a , where a is a scalar and B is a Matrix, to make a matrix of booleans the size of B, where each boolean says whether B is equal to a. By combining this with any() , we see that any([1:7] == period will be true when the period is between 1 to 7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM