问题
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