Local Extrema - MATLAB Cody - MATLAB Central

Problem 54730. Local Extrema

Difficulty:Rate
Given a 2D (m,n>1) matrix, replace an element if it is not a local extrema (minima/maxima), with 0 (zero).
The comparison criteria for an extrema should be strict (> or <). (See example #1)
Check the 3 neighbours of the corner points, 5 for elements on the edge and 8 for elements in the middle.
%Example #1
x=[1 2 3
2 3 1
3 1 2];
y=[1 0 0
0 0 0
0 0 0];
%Example #2
x=[1 4 7 33 12 6 17
29 8 20 13 3 -1 2
19 14 26 -8 22 20 4
1 6 4 17 34 14 2
-23 27 31 9 30 3 10];
y=[1 0 0 33 0 0 17
29 0 0 0 0 -1 0
0 0 26 -8 0 0 0
0 0 0 0 34 0 2
-23 0 31 0 0 0 0]
%Example #3
x=[-5 -31 -17 -3 -23 -11
-2 -37 -19 -7 -13 -29];
y=[0 0 0 -3 0 -11
-2 -37 0 0 0 -29];
More test cases might be added later.

Solution Stats

54.55% Correct | 45.45% Incorrect
Last Solution submitted on Jul 18, 2024

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers6

Suggested Problems

More from this Author31

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!