Error on filter() - Subscript indices must either be positive integers or logicals

2 ビュー (過去 30 日間)
Bryan Wilson
Bryan Wilson 2017 年 12 月 14 日
コメント済み: Jan 2017 年 12 月 14 日
I'm trying to use filter() to do a moving average on my data, but I keep getting the error "Subscript indices must either be positive integers or logicals." What's really bothering me is I get the same error when I try running the example on the filter() webpage. Here's the example. It breaks on the y=filter(b,a,x) line.
t = linspace(-pi,pi,100);
rng default %initialize random number generator
x = sin(t) + 0.25*rand(size(t));
windowSize = 5;
b = (1/windowSize)*ones(1,windowSize);
b = [1/5 1/5 1/5 1/5 1/5]
a = 1;
y = filter(b,a,x);
plot(t,x)
hold on
plot(t,y)
legend('Input Data','Filtered Data')

採用された回答

Jan
Jan 2017 年 12 月 14 日
Hi Brian, did you see Walter's comment? Most likely the symbol "filter" was overwritten by a variable. Then the builtin function is "shadowed". If this is your problem:
clear filter
and do not use the name of builtin functions for variables in general.
  2 件のコメント
Bryan Wilson
Bryan Wilson 2017 年 12 月 14 日
Yes! That's exactly right. I had named another variable 'filter.' Changed the variable name and now it works great.
Jan
Jan 2017 年 12 月 14 日
Then Walter has found the problem 12 hours earlier - thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMulticore Processor Targets についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by