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
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
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]
F = @(a)findpeaks(a,'Threshold',3);
C = cellfun(F,num2cell(A,2),'uni',0)
3 件のコメント
Stephen23
2024 年 1 月 17 日
V = [1,1,2,4,2,-1]
X = findpeaks(V)
Y = islocalmax(V)
By specifying the threshold explicitly then of course I can change what peaks are detected:
X = findpeaks(V, 'Threshold',3)
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!