How to apply MinSeparation on both islocalmin and islocalmax
조회 수: 16 (최근 30일)
이전 댓글 표시
I am using findlocalmin and findlocalmax to find the local extrema of a curve (actually, it's a column of a greyscale image). The problem is that the curve is very quircky, so there are a LOT of local extrema. Now I want to use the MinSeparation property to space the extrema out a bit more. The problem is that this property only works for OR the maxima, OR the minima, as you have to get them using two functions:
A = [0 -0.0053 0.0690 0.1572 0.5036 1.1386 0.9963 0.2337 -0.0711 -0.0479 -0.0589 -0.0452 0.0017 ...
-0.0041 -0.0436 -0.0531 -0.0439 -0.0612 -0.0501 0.0114 0.0099 -0.0540 -0.0644 -0.0451 -0.0698 -0.0418 0.1162 0.2205 0.1490 0.0427 -0.0177...
-0.0495 -0.0595 -0.0507 -0.0215 0.0775 0.1895 0.1314 -0.0051 -0.0310 -0.0203 -0.0438 -0.0484 -0.0447 -0.0638 -0.0591];
x = 1:length(A);
MinMax0 = islocalmax(A,1) | islocalmin(A,1);
MinMax = islocalmin(A,'MinSeparation',2) | islocalmax(A, 'MinSeparation',2);
plot(A,'-'); hold on; plot(x(MinMax0),A(MinMax0),'*'); plot(x(MinMax), A(MinMax),'^'); hold off
So in practice, it is very much possible that points within the MinSeparation range are still on the curve, as the MinSeparation doesn't work over the min and max function together, as you can see.
This is especially problematic for my application, as it often happens that the peak as well as the two adjecent points are selected (i.e. 3 consecutive points), and in further steps this poses problems; in that case I would only want to keep the peak and not the adjecent points.
Is there any way to harmonize this effect over the two functions?
댓글 수: 2
Alekhya Hati
2023년 3월 24일
The functions also have another name-value argument called 'Prominence'. I think you should play around with that and apply the value which works in your case. Also use the 'FlatSelection' argument.
Mathieu NOE
2023년 3월 27일
hello
what points in your plot would you consider as valid then ?
a picture is sometimes better to help us understand your problem
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!