Hey guys! I need to find the low points

2 views (last 30 days)
Zachary Holmes
Zachary Holmes on 12 Nov 2015
Answered: Thorsten on 12 Nov 2015
(a) You are to write a Matlab function called findLowPoints. The function takes in one parameter: a vector of real numbers (suppose the length of the vector is greater than 1). Each number in the array represents the height of a point. The function will return the height of low points in a vector. The sequence of the heights must be the same as they appear in the input array. A point is defined as a low point if its height is lower that the one on its left and it is also lower that the one on its right. Note that if it is the first point, it only needs to be lower than the second point; and if it is the last point, its height only needs to be lower than the point to it’s left. For example, given an array of real number as follows:
h = [-15, -12.5, -23, -9.2, 1.4, 3.4, 2.5, 10.09, 20]
then
lowPoints = findLowPoints(h) should set lowPoints to the returned value [ -15, -23, 2.5 ].

Answers (2)

Image Analyst
Image Analyst on 12 Nov 2015
You mean like this:
lowValues = h(imregionalmin(h))
imregionalmin() is the built-in function (in the Image Processing Toolbox) that finds low points, so all you need to do is call it.

Thorsten
Thorsten on 12 Nov 2015
dh = diff([realmax h realmax]) > 0;
h(~dh(1:end-1) & dh(2:end))

Categories

Find more on MATLAB 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!