MATLAB: Trying to do 1D convolution without using inbuilt functions.

convolution

Hi, I used the following code to do 1D convolution. But getting error:>>
a=[1 2 3];
b=[4 5 6];
K= length(a)+length(b)-1
for i=1:k
K_out(i)= 0
for j=1:length(b)
K_out(i)= K_out(i)+ a(i-j)*b(j)
end
end
The error is: Undefined function or variable 'k'.
But I already defined K.
Thanks

Best Answer

You defined a variable K, and then tried to use k.
MATLAB is case sensitive, you cannot use upper/lowercase interchangeably.