trying to do 1D convolution without using inbuilt functions.

10 ビュー (過去 30 日間)
satnam singh
satnam singh 2016 年 5 月 2 日
回答済み: Sk Group 2021 年 10 月 25 日
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

採用された回答

Stephen23
Stephen23 2016 年 5 月 2 日
編集済み: Stephen23 2016 年 5 月 2 日
You defined a variable K, and then tried to use k.
MATLAB is case sensitive, you cannot use upper/lowercase interchangeably.
  1 件のコメント
satnam singh
satnam singh 2016 年 5 月 2 日
Thanks...but this code still not working..as while computing (i-j) goes to zero or negative the Matlab cannot access the Zero or negative index as the index value is always positive. The error is: Attempted to access a(0); index must be a positive integer or logical.
Please suggest a way out.

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

その他の回答 (1 件)

Sk Group
Sk Group 2021 年 10 月 25 日
Convolution without conv function in MATLAB | Complete CODE | Explanation | Example And Output

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by