should i us if/eslse if or int.
2 views (last 30 days)
Show older comments
Danielle deWaard on 29 Jul 2021
Answered: Kshitij Chhabra on 4 Aug 2021
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.
Cris LaPierre on 29 Jul 2021
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.
Kshitij Chhabra on 4 Aug 2021
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:
elseif(days>=2.5 & days<=17.63)
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!