islocalmin
Find local minima
Syntax
Description
specifies additional parameters for finding local minima using one or more name-value pair arguments. For example,TF
= islocalmin(___,Name,Value
)islocalmin(A,'SamplePoints',t)
finds local minima ofA
with respect to the time stamps contained in the time vectort
.
[
also returns theprominencecorresponding to each element ofTF
,P
] = islocalmin(___)A
for any of the previous syntaxes.
Examples
Local Minima in Vector
Compute and plot the local minima of a vector of data.
x = 1:100; A = (1-cos(2*pi*0.01*x)).*sin(2*pi*0.15*x); TF = islocalmin(A); plot(x,A,x(TF),A(TF),'r*')
Minima in Matrix Rows
Create a matrix of data, and compute the local minima for each row.
A = -25*diag(ones(5,1)) + rand(5,5); TF = islocalmin(A,2)
TF =5x5 logical array0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0
Separated Minima
Compute the local minima of a vector of data relative to the time stamps in the vectort
. Use the'MinSeparation'
parameter to compute minima that are at least 45 minutes apart.
t = hours(linspace(0,3,15)); A = [2 4 6 4 3 7 5 6 5 10 4 -1 -3 -2 0]; TF = islocalmin(A,'MinSeparation',minutes(45),'SamplePoints',t); plot(t,A,t(TF),A(TF),'r*')
Flat Minima Regions
Specify a method for indicating consecutive minima values.
Compute the local minima of data that contains consecutive minima values. Indicate the minimum of each flat region based on the first occurrence of that value.
x = 0:0.1:5; A = max(-0.75, sin(pi*x)); TF1 = islocalmin(A,'FlatSelection','first'); plot(x,A,x(TF1),A(TF1),'r*')
Indicate the minimum of each flat region with all occurrences of that value.
TF2 = islocalmin(A,'FlatSelection','all'); plot(x,A,x(TF2),A(TF2),'r*')
Prominent Minima
Compute the local minima of a vector of data and their prominence, and then plot them with the data.
x = 1:100; A = peaks(100); A = A(50,:); [TF1,P] = islocalmin(A); P(TF1)
ans =1×22.7585 1.7703
plot(x,A,x(TF1),A(TF1),'r*') axistight
Compute the most prominent minimum in the data by specifying a minimum prominence requirement.
TF2 = islocalmin(A,'MinProminence',2); plot(x,A,x(TF2),A(TF2),'r*') axistight
Input Arguments
A
—Input data
vector|matrix|multidimensional array|table|timetable
Input data, specified as a vector, matrix, multidimensional array, table, or timetable.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|logical
|table
|timetable
dim
—Operating dimension
positive integer scalar
Operating dimension, specified as a positive integer scalar. By default,islocalmin
operates along the first dimension whose size does not equal 1.
For example, ifA
is a matrix, thenislocalmin(A,1)
operates along the rows ofA
, computing local minima for each column.
islocalmin(A,2)
operates along the columns ofA
, computing local minima for each row.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
Name-Value Pair Arguments
Specify optional comma-separated pairs ofName,Value
arguments.Name
is the argument name andValue
is the corresponding value.Name
must appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN
.
TF = islocalmin(A,'MinProminence',2)
'MinProminence'
—Minimum prominence
0(default) |nonnegative scalar
Minimum prominence, specified as the comma-separated pair consisting of'MinProminence'
and a nonnegative scalar.islocalmin
returns only local minima whose prominence is at least the value specified.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
'ProminenceWindow'
—Prominence window
positive integer scalar|two-element vector of positive integers|positive duration scalar|two-element vector of positive durations
Prominence window, specified as the comma-separated pair consisting of'ProminenceWindow'
and a positive integer scalar, a two-element vector of positive integers, a positive duration scalar, or a two-element vector of positive durations. The value defines a window of neighboring points for which to compute the prominence for each local minimum.
When the window value is a positive integer scalark, then the window is centered about each local minimum and containsk-1neighboring elements. Ifkis even, then the window is centered about the current and previous elements. If a local minimum is within a flat region, thenislocalmin
treats the entire flat region as the center point of the window.
When the value is a two-element vector[b f]
of positive integers, then the window contains the local minimum,b
elements backward, andf
elements forward. If a local minimum is within a flat region, then the window startsb
elements before the first point of the region and endsf
elements after the last point of the region.
When the input data is a timetable or when'SamplePoints'
is specified as adatetime
orduration
vector, the window value must be of typeduration
, and the window is computed relative to the sample points.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|duration
'FlatSelection'
—Flat region indicator
'center'
(default) |'first'
|'last'
|'all'
Flat region indicator for when a local minimum value is repeated consecutively, specified as the comma-separated pair consisting of'FlatSelection'
and one of the following:
'center'
— Indicate only the center element of a flat region as the local minimum. The element ofTF
corresponding to the center of the flat is 1, and is 0 for the remaining flat elements.'first'
— Indicate only the first element of a flat region as the local minimum. The element ofTF
corresponding to the start of the flat is 1, and is 0 for the remaining flat elements.'last'
— Indicate only the last element of a flat region as the local minimum. The element ofTF
corresponding to the end of the flat is 1, and is 0 for the remaining flat elements.'all'
— Indicate all the elements of a flat region as the local minima. The elements ofTF
corresponding to all parts of the flat are 1.
When using the'MinSeparation'
or'MaxNumExtrema'
name-value pairs, flat region points are jointly considered a single minimum point.
'MinSeparation'
—Minimum separation
0(default) |nonnegative scalar
Minimum separation between local minima, specified as the comma-separated pair consisting of'MinSeparation'
and a nonnegative scalar. The separation value is defined in the same units as the sample points vector, which is[1 2 3 ...]
默认情况下。当分离值大于than 0,islocalmin
selects the smallest local minimum and ignores all other local minima within the specified separation. This process is repeated until there are no more local minima detected.
When the sample points vector has typedatetime
, the separation value must have typeduration
.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|duration
'MaxNumExtrema'
—Maximum number of minima
positive integer scalar
Maximum number of minima detected, specified as the comma-separated pair consisting of'MaxNumExtrema'
and a positive integer scalar.islocalmin
finds no more than the specified number of most prominent minima, which is the length of the operating dimension by default.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
'SamplePoints'
—Sample points
vector
Sample points, specified as the comma-separated pair consisting of'SamplePoints'
and a vector. The sample points represent the location of the data inA
. Sample points do not need to be uniformly sampled, but must be sorted with unique elements. By default, the sample points vector is[1 2 3 ...]
.
islocalmin
does not support this name-value pair when the input data is a timetable.
Data Types:double
|single
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|datetime
|duration
'DataVariables'
—Table variables
variable name|单元阵列的变量名|numeric vector|logical vector|有趣的ction handle
Table variables, specified as the comma-separated pair consisting of'DataVariables'
and a variable name, a cell array of variable names, a numeric vector, a logical vector, or a function handle. The'DataVariables'
value indicates which columns of an input table or timetable to operate on. This value can be one of the following:
A character vector specifying a single table variable name
A cell array of character vectors where each element is a table variable name
A vector of table variable indices
A logical vector whose elements each correspond to a table variable, where
true
includes the corresponding variable andfalse
excludes itA function handle that takes a table variable as input and returns a logical scalar
The specified table variables must have numeric orlogical
type.
Example:'Age'
Example:{'Height','Weight'}
Example:@isnumeric
Data Types:char
|cell
|double
|single
|logical
|有趣的ction_handle
Output Arguments
TF
— Local minima indicator
vector | matrix | multidimensional array
Local minima indicator, returned as a vector, matrix, or multidimensional array.TF
is the same size asA
.
Data Types:logical
P
— Prominence
vector | matrix | multidimensional array
Prominence, returned as a vector, matrix, or multidimensional array.P
is the same size asA
.
If the input data has a signed or unsigned integer type, thenP
is an unsigned integer.
More About
Prominence of Local Minimum
The prominence of a local minimum (or valley) measures how the valley stands out with respect to its depth and location relative to other valleys.
To measure the prominence of a valley, first extend a horizontal line from the valley to the left and to the right of the valley. Find where the line intersects the data on the left and on the right, which will either be another valley or the end of the data. Mark these locations as the outer endpoints of the left and right intervals. Next, find the highest peak in both the left and right intervals. Take the smaller of these two peaks, and measure the vertical distance from that peak to the valley. This distance is the prominence.
For a vectorx
, the largest prominence is at mostmax(x)-min(x)
.
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
Usage notes and limitations:
Tall timetables are not supported.
You must specify a value for the
'ProminenceWindow'
name-value pair.The
'MaxNumExtrema'
,'MinSeparation'
, and'SamplePoints'
name-value pairs are not supported.The value of
'DataVariables'
cannot be a function handle.
For more information, seeTall Arrays.
C / c++代码生成
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
You must enable support for variable-size arrays.
The
'ProminenceWindow'
name-value pair is not supported.Tables are not supported.
See Also
Introduced in R2017b
Open Example
A modified version of this example exists on your system. Do you want to open this version instead?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)