Array indices must be positive integers or logical values.

1 visualización (últimos 30 días)
Marc Elmeua
Marc Elmeua el 9 de Sept. de 2021
Comentada: Marc Elmeua el 12 de Sept. de 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);
Thanks in advance!

Respuesta aceptada

Dave B
Dave B el 9 de Sept. de 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?
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);

Más respuestas (0)

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by