# Array indices must be positive integers or logical values.

3 Ansichten (letzte 30 Tage)
Marc Elmeua am 9 Sep. 2021
Kommentiert: Marc Elmeua am 12 Sep. 2021
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);
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Dave B am 9 Sep. 2021
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?
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);
##### 1 KommentarKeine anzeigenKeine ausblenden
Marc Elmeua am 12 Sep. 2021
Thanks! That was it!!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by