[英]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?
我被卡在最后一行,如何检查期间是否在1到几天之内?
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. 您可以使用语句
B == a
,其中a是一个标量,B是一个矩阵,以使布尔值的矩阵成为B的大小,其中每个布尔值都表示B是否等于a。 By combining this with any()
, we see that any([1:7] == period
will be true when the period is between 1 to 7. 通过将其与
any()
结合,我们可以看到,当周期在1到7之间时, any([1:7] == period
将是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.