Array indices must be positive integers or logical values.

2 次查看(过去 30 天)
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 个)

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by