Hello, I need a code that gets the local minimum of a histogram by using for loops.
2 views (last 30 days)
Walter Roberson on 23 May 2022
Initialize to index 1.
Initialize to "potentially in a local minima"
If you are potentially in a local minima, check to see if the value of the next location is greater than the current value. If it is, then you were in a local minima, and record it, and flip out of potentially mode. But if the value of the next location is equal to the current value, maintain "potentially" mode and continue to the next location. If the value of the next location is less than the current value, make that the new current value and continue in "potentially" mode. If you ran off the end of the array then you were in a local minima.
You should be able to do a similar analysis for the case where you are not currently in "potentially" mode.