Effacer les filtres
Effacer les filtres

Find peaks in a matrix containing zeros

1 vue (au cours des 30 derniers jours)
Askeladden2
Askeladden2 le 17 Jan 2024
Commenté : Askeladden2 le 17 Jan 2024
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 commentaire
Dyuman Joshi
Dyuman Joshi le 17 Jan 2024
Modifié(e) : Dyuman Joshi le 17 Jan 2024
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?

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 17 Jan 2024
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 commentaires
Stephen23
Stephen23 le 17 Jan 2024
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.
Askeladden2
Askeladden2 le 17 Jan 2024
Thank you for your quick response!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by