should i us if/eslse if or int.

1 回表示 (過去 30 日間)
Danielle deWaard
Danielle deWaard 2021 年 7 月 29 日
回答済み: Kshitij Chhabra 2021 年 8 月 4 日
I am having trouble with a code that is depicting days. i have three different rates. one being the daily rate used for 1-2.4 days. weekly rate starts from 2.5-17.63. and monthly goes from 17.65-30 days.
At first thought, the If/Elseif seems the most logical until it becomes something like 34 days, where i need the program to depictthat it is 34 days and now it needs to add the monthly and the weekly or 61 days - where it now needs to depict two monthly rates and then a daily rate. and so on and so forth
I dont know if someone has any advice or more knowledge on the intergration function and if that is a route i should consider taking instead.
Thank you in advance for any help.
  1 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 7 月 29 日
I understand the issue with number of days, and how an if/else statement can possible help out there. You lost me, though, when you started talking about integration. I think we are missing some important details necessary for understanding your question. Can you please clarify? If you have some code already, please share that as well.

サインインしてコメントする。

回答 (1 件)

Kshitij Chhabra
Kshitij Chhabra 2021 年 8 月 4 日
From my understanding of the question, you want to implement an if/else if ladder to calculate the rate which you should use for the following day. An approach which I can suggest is using the mod function along with division in MATLAB.
In your case, lets say that you find the rate for 68 days and you have a dailyRate, weeeklyRate and a monthlyRate, you can compute the final rate as follows:
input=68;
months=floor(input/30);
days=mod(input,30) ;
rate=0;
if(days<=2.4)
rate=dailyRate;
elseif(days>=2.5 & days<=17.63)
rate=weeklyRate;
else
rate=monthlyRate;
end
rate=monthlyRate*months+rate;

カテゴリ

Help Center および File ExchangeExponents and Logarithms についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by