How to solve error of index exceeds number of array elements?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I am using MATLAB R2020a on MacOS. I am trying to find the exponentially weighted moving mean of my signal 'cycle_periods' using the dsp.MovingAverage function algorithm. I am trying to also remove outliers on an element by element basis in real-time. However, I keep getting this error:
% Calculate successive weights to test how they change with different FF
% values
lambda = 0.1;
w = zeros(length(cycle_periods),1);
w(1) = 1; % initialize the weight for the first sample
for i = 2:length(cycle_periods)
w(i) = lambda*w(i-1) + 1; % calculate the successive weights
end
% Calculate moving mean with weights manually
x = zeros(length(cycle_periods), 1);
x(1) = cycle_periods(1);
for i = 2:length(cycle_periods)
x(i) = (1 - 1/w(i))*x(i - 1) + (1/w(i))*cycle_periods(i);
if x(i) > 1.5*x(i - 1) % Remove high outliers
x(i) = [];
elseif x(i) < 0.5*x(i - 1) % Remove low outliers
x(i) = [];
end
end
Index exceeds the number of array elements (45).
Error in R09_11_20 (line 86)
x(i) = (1 - 1/w(i))*x(i - 1) + (1/w(i))*cycle_periods(i);
Any help would be much appreciated, thanks!
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!