필터 지우기
필터 지우기

Find peaks in a matrix containing zeros

조회 수: 1 (최근 30일)
Askeladden2
Askeladden2 2024년 1월 17일
댓글: Askeladden2 2024년 1월 17일
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.
Askeladden2
Askeladden2 2024년 1월 17일
Thank you for your quick response!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by