필터 지우기
필터 지우기

For loop not working. Array indices must be positive integers or logical values.

조회 수: 1 (최근 30일)
matlabgod
matlabgod 2018년 12월 10일
다시 열림: Walter Roberson 2018년 12월 20일
Im Trying to implement an FIR difference equation where the output y is the average sum of a set number of values(M) of the input(x).
f0=10;
fs= 2*50*f0;
ts=1/fs;
tw=2;
t=0:ts:tw;
x=1*square(2*pi*f0*t);
y = zeros(1,length(x));
k=6;
M=k;
for i=1:k
for j = 1:M
y(j) = y +(1/(M+1))*x(i-j);
end
end
figure, plot(t,y, 'k')
ylim([-1 1])

답변 (1개)

James Tursa
James Tursa 2018년 12월 10일
This line on the first iteration when i=1 and j=1:
y(j) = y +(1/(M+1))*x(i-j);
You are indexing x(0). Also, you are trying to assign a vector (y on the rhs) into an element y(j) which isn't going to work either. This needs to be fixed.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by