Ibaghdadi
Newbie level 6
for loop matlab
Hi;
I want to use the convolution in matlab, using for loop so i did the following:
that did not work and I got the following error:
why?
Added after 45 minutes:
ok i found a huge problem in my code which is mostly i am starting the index in zero not in 1 so i did the following:
now i get a new error:
??? Index exceeds matrix dimensions.
Hi;
I want to use the convolution in matlab, using for loop so i did the following:
Code:
n=6;
x=[1 2 2 3];
h=[2 -1 3];
y=zeros(1,n);
for i=0:n
for j=0:i
y(j)=y(j)+x(j)*h(i-j);
end
end
that did not work and I got the following error:
Code:
??? Subscript indices must either be real positive integers or logicals.
why?
Added after 45 minutes:
ok i found a huge problem in my code which is mostly i am starting the index in zero not in 1 so i did the following:
Code:
n=6;
x=[1 2 2 3];
h=[2 -1 3];
y=zeros(1,n);
for i=1:n
for j=1:i
y(i)=y(i)+x(j)*h(i-j+1)
end
end
now i get a new error:
??? Index exceeds matrix dimensions.