Find local extremes and flat intermediate values with average values
Show older comments
How do I find the location of the local extreme values of a large data set, and change the values between each two extreme values by their average value?
Answers (1)
Image Analyst
on 6 Mar 2022
Try this
data = randi(100, 1, 40)
minValue = min(data(:))
maxValue = max(data(:))
meanValue = mean(data(:))
linearIndex1 = find(data(:) == minValue) % Find all occurences of the min value.
linearIndex2 = find(data(:) == maxValue) % Find all occurences of the max value.
allIndexes = sort([linearIndex1; linearIndex2], 'ascend')
data(allIndexes(1) : allIndexes(end)) = meanValue
1 Comment
Humberto Munoz
on 7 Mar 2022
Categories
Find more on Descriptive Statistics 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!