MATLAB: Matrix dimensions must agree

dimensions

Hi,
Even though I use acceptable matrix dimensions, I am getting Matrix dimensions error. dft matrix size is: 500×332 H_blurring matrix size is: 332×500 I multiply these 2 matrix.
"Error using .*
Matrix dimensions must agree."
if true
% A=load('Blurred.mat');
B=A.blurred;
image = im2double(B);
[rows, cols] = size(image);
figure; imshow(image,[]); title('Original image');
%%Blurring (atmospheric turbulence)
dft = fftshift(fft2(image));
k = 0.002;
u0 = floor(rows/2)+1;
v0 = floor(cols/2)+1;
u = (1:rows)-u0;
v = (1:cols)-v0;
[U,V] = meshgrid(u,v);
D = (U.^2+V.^2);
H_blurring = exp(-k*(D.^(5/6)));
figure;
imshow(dft); title('dft');
figure;
imshow(H_blurring); title('Blurred');
result = dft .* H_blurring;
end

Best Answer

Ismail - using the .* implies that you want to do element-wise multiplication i.e. multiply each element of one matrix with the corresponding (same row and column) element of the other matrix. Since your matrices are of different dimensions then the error makes sense. Just change this line to
result = dft * H_blurring;
and you will now be doing the usual matrix multiplication.
Related Question