Array indices must be positive integers or logical values.

조회 수: 5 (최근 30일)
Marc Elmeua
Marc Elmeua 2021년 9월 9일
댓글: Marc Elmeua 2021년 9월 12일
I get this error when indexing a variable with peaks found with findpeaks, only when I specify min peak distance and height. Any ideas why this is happening?
acc = ACClowFilt;
peakdistance = 0.5;
epoch = 0.3;
fs = 1000
accdetrend = detrend(acc,0);
% [~, locs] = findpeaks(accdetrend,fs,'MinPeakDistance',peakdistance,'MinPeakHeight',max(acc)*epoch);
[~, locs] = findpeaks(accdetrend);
strideid = zeros(length(acc),1);
strideid(locs) = 1;
strideid = cumsum(strideid);
Thanks in advance!

채택된 답변

Dave B
Dave B 2021년 9월 9일
It looks like when you gave findpeaks a sampling rate it converted the units to time:
From the findpeaks documentation page:
[___] = findpeaks(data,Fs) specifies the sample rate, Fs, of the data. The first sample of data is assumed to have been taken at time zero. locs and w are converted to time units.
If you want to keep doing it that way (so your distance is in time units), you could just multiply back out when setting strideid?
load ACClowFilt.mat
acc = ACClowFilt;
peakdistance = 0.5;
epoch = 0.3;
fs = 1000;
accdetrend = detrend(acc,0);
[~, locs] = findpeaks(accdetrend,fs,'MinPeakDistance',peakdistance,'MinPeakHeight',max(acc)*epoch);
%[~, locs] = findpeaks(accdetrend);
strideid = zeros(length(acc),1);
strideid(locs*fs) = 1;
strideid = cumsum(strideid);

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by