should i us if/eslse if or int.
2 次查看(过去 30 天)
显示 更早的评论
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
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
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;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Exponents and Logarithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!