problem of using findpeaks

조회 수: 3 (최근 30일)
jie hu
jie hu 2023년 11월 28일
답변: Chunru 2023년 11월 28일
I have two vectors of time (datetime formate) and elevation, but there is an error to use findpeaks(elev,time), saying "Expected X to be strictly increasing."

답변 (2개)

Star Strider
Star Strider 2023년 11월 28일
My guess is that the datetime values are not considered to be monotonically increasing because they span multiple years.
Try this as a work-around —
LD = load('19year.mat');
elev = LD.elev;
timing = LD.timing;
[pks,plocs] = findpeaks(elev);
[vys,vlocs] = findpeaks(-elev);
figure
plot(timing, elev, 'DisplayName','Data')
hold on
plot(timing(plocs), pks, '^r', 'MarkerSize',2.5, 'DisplayName','Peaks')
plot(timing(vlocs), -vys, 'vg', 'MarkerSize',2.5, 'DisplayName','Valleys')
hold off
grid
xlabel('timing')
ylabel('elev')
legend('Location','best')
figure
plot(timing, elev, 'DisplayName','Data')
hold on
plot(timing(plocs), pks, '^r', 'DisplayName','Peaks')
plot(timing(vlocs), -vys, 'vg', 'DisplayName','Valleys')
hold off
grid
xlabel('timing')
ylabel('elev')
legend('Location','best')
xlim([timing(1) timing(500)])
.

Chunru
Chunru 2023년 11월 28일
load(websave("19year.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1553817/19year.mat"))
% It seems that timing contains duplcate data.
% fild peaks require x-axis to be monotonically increasing.
% Workaround:
% sort the data
[timing, i] = sort(timing);
elev = elev(i);
% find the peaks and location
[pks, locs] = findpeaks(elev, MinPeakProminence=1);
plot(timing, elev);
hold on
plot(timing(locs), pks, 'rv', 'Markersize', 5)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by