Do 1-D convolution along each row of a matrix

岁酱吖の 提交于 2019-12-11 11:23:10

问题


Did a quick search and couldn't find much about this. Say I have a 2D matrix and a 1D 'response function'. I want to convolve each row of the 2D matrix with the response function. I can do this by:

for i=1:numrows
    answer(:,i) = conv(2dmatrix(:,i),response_function,'same');
end

but it's super slow! Any tips to accelerate this?

Thanks


回答1:


This code reproduces your results on randomly generated matrices:

conv2(response_function,1,2dmatrix,'same')

conv2 allows you to convolute along rows and columns separately, so do nothing to the rows, 1, and convolve the columns by response_function.

To convolve along each row, swap the order of the first two function arguments.



来源:https://stackoverflow.com/questions/29292314/do-1-d-convolution-along-each-row-of-a-matrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!