繁体   English   中英

我如何在matlab中的if语句中编写1至7天的条件?

[英]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

我在这里进行计算,并检查一些条件以获取租车费用。 我被卡在最后一行,如何检查期间是否在1到几天之内?

替代解决方案:

您可以使用语句B == a ,其中a是一个标量,B是一个矩阵,以使布尔值的矩阵成为B的大小,其中每个布尔值都表示B是否等于a。 通过将其与any()结合,我们可以看到,当周期在1到7之间时, any([1:7] == period将是正确的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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