MATLAB: Find peaks of a vector contains nan values

find peaks of a vector contains nan valuesMATLAB

b=[ NaN NaN NaN NaN 0.0691 0.0697 0.0760 0.0829 0.0891 0.0907 0.0952 0.0941 0.0964 0.0963 0.1003 0.0913 0.0775 0.0725 0.0799 0.0843 0.0677 0.0449 0.0280 0.0212 0.0184 0.0163 0.0143 0.0123 0.0087]
[~,lct] = findpeaks(b,'MinPeakheight',0.05,'MinPeakDistance',1);
after running this statement
i am getting warning and my lct is
lct = 1×0 empty double row vector
it contains nothing. and warning is
Warning: Invalid MinPeakHeight. There are no data points greater than
MinPeakHeight.
> In findpeaks>removePeaksBelowMinPeakHeight (line 516)
In findpeaks (line 147)
can you please solve my problem. thanking you sir

Best Answer

The code in your orginial question differs from the code you provided in the comments under your question. In your original code, input values were all positive. In your second version of code, input values were negative an you used different MinPeakHeight values.
Initial version
This is the code exactly copied form your question. I added the figure. Note that 'b' and 'MinPeakHeight' are positive.
b=[ NaN NaN NaN NaN 0.0691 0.0697 0.0760 0.0829 0.0891 0.0907 0.0952 0.0941 0.0964 0.0963 0.1003 0.0913 0.0775 0.0725 0.0799 0.0843 0.0677 0.0449 0.0280 0.0212 0.0184 0.0163 0.0143 0.0123 0.0087]
[~,lct] = findpeaks(b,'MinPeakheight',0.05,'MinPeakDistance',1);
% figure

figure
plot(b, '-b')
hold on
plot(lct, b(lct), 'm*') %labelpeaks
Incorrect version
This is the code exactly copied from your comment where the sign of 'b' and 'MinPeakHeight' are negative.
b=[ NaN NaN NaN NaN 0.0691 0.0697 0.0760 0.0829 0.0891 0.0907 0.0952 0.0941 0.0964 0.0963 0.1003 0.0913 0.0775 0.0725 0.0799 0.0843 0.0677 0.0449 0.0280 0.0212 0.0184 0.0163 0.0143 0.0123 0.0087]
[~,lct] = findpeaks(-b,'MinPeakHeight',-0.0605,'MinPeakDistance',1);
% figure
figure
plot(-b, 'b-')
It produces a warning message:
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
If you look at the plot of -b below, there are no peaks that are above -0.06 which is where you've set the threshold for the minimum peak height (horizontal reference line).
190212 150146-Figure 1.jpg