Borrar filtros
Borrar filtros

Convolution without convolution function

4 visualizaciones (últimos 30 días)
Randa
Randa el 30 de Nov. de 2022
Comentada: Rena Berman el 5 de Dic. de 2022
<<
>>
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

Respuestas (1)

Image Analyst
Image Analyst el 30 de Nov. de 2022
I have a manual convolution demo. See attached, and use it if you want.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by