フィルターのクリア

Can these operations be vectorized?

1 回表示 (過去 30 日間)
Vinod S
Vinod S 2012 年 10 月 29 日
n1=-64:63;
Inter=sinc(n1/9);
Poly=reshape(Inter,8,16);
X=repmat([1,-1],1,10);
for i=1:8
A(i,:)=conv(Poly(i,:),X);
end
So in this small program I am storing in Matrix A, the output of a convolution operation. Each Row of A represents the output for one iteration. Now my Question is can I get this done without using the for loop. Like by using bsxfun or anything? Please suggest.

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 10 月 29 日
編集済み: Andrei Bobrov 2012 年 10 月 30 日
bad variant, so use loop for .. end
s = size(Poly);
n = numel(X);
ii = bsxfun(@minus,ones(s(1),1)*(1:s(2)+n-1),reshape((0:n-1).',1,1,[]));
i01 = ii >= 1 & ii <= s(2);
m = repmat(Poly,[1,1,n]);
out0 = i01 + 0;
out0(i01) = m;
A = sum(bsxfun(@times,out0,reshape(X,1,1,[])),3);
or
s = size(Poly);
n = numel(X);
i1 = tril(fliplr(flipud(tril(true(s(2)+n-1,n)))));
i2 = repmat(reshape(i1,1,s(2)+n-1,[]),s(1),1);
out1 = i2 + 0;
out1(i2) = bsxfun(@times,repmat(Poly,[1,1,n]),reshape(X,1,1,[]));
out = sum(out1,3);

その他の回答 (2 件)

Sachin Ganjare
Sachin Ganjare 2012 年 10 月 29 日
編集済み: Sachin Ganjare 2012 年 10 月 29 日

José-Luis
José-Luis 2012 年 10 月 29 日
編集済み: José-Luis 2012 年 10 月 29 日
There are ways, but it will probably be slower. For loops are not necessarily bad. Look at the answer here for a problem similar to yours.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by