簡體   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