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!