Convolution without convolution function
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
<<
>>
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
Réponses (1)
Image Analyst
le 30 Nov 2022
I have a manual convolution demo. See attached, and use it if you want.
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!