Indexing error using sum
古いコメントを表示
I have written a simple code that performs a moving average smoothing algorithm (it averages n adjacent bins to a single bin similar to Matlab's smooth):
signal = ones(1,30); % Random sample
n=3; % An odd number (filter span)
for i = k : length(signal)-k
NewSignal(i,:) = sum(signal(i-n:i+n,:))/n;
end
However, the second to last line results in the following error:
%Index in position 1 is invalid. Array indices must be positive integers or logical values.
So, what is the cause of this error? And what would be a solution?
Any explanation would be greatly appreciated.
3 件のコメント
madhan ravi
2019 年 5 月 19 日
signal(n-i:i+n,:)
% ^^^---- perhaps you meant this?
KALYAN ACHARJYA
2019 年 5 月 19 日
Perhaps reflects error of exceeds array bounds, in this case too.
madhan ravi
2019 年 5 月 19 日
Didn't test while commenting.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Signal Attributes and Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!