Find peaks in a matrix containing zeros

1 次查看(过去 30 天)
Dear All Community Members,
I have two matrices, 'A' and 'B'. Matrix 'A' represents the time history of velocities, while matrix 'B' represents the corresponding times. I want to extract all the peak velocity values from matrix 'A' that are above a threshold value of 3.
Matrix A is as follows:
A=[ 1 3 -1 1 5 -1 0;1 6 3 -2 0 0 0;2 3 9 -2 1 11 -1;4 1 -2 8 5 0 0;2 -2 6 -1 0 0 0;-1 13 -2 0 0 0 0];
Matrix B is as follows:
B=[1 1.5 2.5 3 3.5 4 0;1.5 3 5 6 0 0 0;0.5 2 2.5 2.75 3 4 5;2 4 4.25 4.5 6 0 0;1 2 3 4 0 0 0;0.5 3 4 0 0 0 0];
Specifically, I am looking to extract the value 5 from the first row, the value 6 from the second row, the values 9 and 11 from the third row, and then values 8,6,13 from the from the fourth and to the last row in matrix A.
I have tried the findpeaks function, but I am getting errors because of the ending zeros in matrix B.
Can anyone help me out?
Thank you in advance.
  1 个评论
Dyuman Joshi
Dyuman Joshi 2024-1-17
编辑:Dyuman Joshi 2024-1-17
I am not sure if I get the logic used to extract the values.
In the 4th row, 4 is above 3, but they are not extracted.
How does the values from B come into play here?

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2024-1-17
A = [1,3,-1,1,5,-1,0;1,6,3,-2,0,0,0;2,3,9,-2,1,11,-1;4,1,-2,8,5,0,0;2,-2,6,-1,0,0,0;-1,13,-2,0,0,0,0]
A = 6×7
1 3 -1 1 5 -1 0 1 6 3 -2 0 0 0 2 3 9 -2 1 11 -1 4 1 -2 8 5 0 0 2 -2 6 -1 0 0 0 -1 13 -2 0 0 0 0
F = @(a)findpeaks(a,'Threshold',3);
C = cellfun(F,num2cell(A,2),'uni',0)
C = 6×1 cell array
{[ 5]} {[ 6]} {[9 11]} {[ 8]} {[ 6]} {[ 13]}
  3 个评论
Stephen23
Stephen23 2024-1-17
V = [1,1,2,4,2,-1]
V = 1×6
1 1 2 4 2 -1
X = findpeaks(V)
X = 4
Y = islocalmax(V)
Y = 1×6 logical array
0 0 0 1 0 0
By specifying the threshold explicitly then of course I can change what peaks are detected:
X = findpeaks(V, 'Threshold',3)
X = 1×0 empty double row vector
Clearly 4 is not >=3 compared to the 2's on either side, so it is (according to my requirement) not a maxima. In fact, there are no maxima in that vector according to the threshold that I specified.
"but then the labelling that it finds the local maxima is plainly wrong and 'maxima' should be removed from the documentation."
I do not follow your argument: the definition of what is a local maxima depends on the prominence, the window, etc... I do not see what is "plainly" wrong here.

请先登录,再进行评论。

更多回答(0 个)

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by