Convolution without convolution function

조회 수: 6 (최근 30일)
Randa
Randa 2022년 11월 30일
댓글: Rena Berman 2022년 12월 5일
<<
>>
So I have two square matrices of different sizes. I want to multiply each element of each matrix, sum them, then place the results(column by column)in another output matrix with the same size of the bigger matrix. In order to do that, I have to pad the bigger matrix and incorporate a for loop for the smaller matrix inside the bigger matrix where is shifts by one every iteration and performs the calculations. I also have to incorporate another for loop for the bigger matrix where I can perform those calculations(multiplying then summing)but my code doesn’t work for every size:
function homework M1=rand(7) M2=eye(4)
n=size(M1)-size(M2);%subtract size M2 from size M1 to get the right output padding size A=padarray(M1,n,"post"); %padding M1 with the padded size Output=zeros(size(M1)); %output matrix,set it first to zero
for i=1:size(A,1) for j=1:size(A,2) temp=A(i:i+n,j:j+n).*M2; Output(i,j)=sum(temp(:)); end end display(Output) end

답변 (1개)

Image Analyst
Image Analyst 2022년 11월 30일
I have a manual convolution demo. See attached, and use it if you want.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by