Matrix dimensions must agree.

1 view (last 30 days)
Soong Wei Kang
Soong Wei Kang on 9 Jul 2020
Commented: madhan ravi on 9 Jul 2020
I keep getting the error message : Matrix dimensions must agree. from the code "A = abs(imgA).*exp(1*(1i*rando*pi)); " May i know what is the solution for this?
%% Mesh
close all
n=145; % Number of pixels on one axis
rmax=1; % Normalized radius
X=2*rmax*(-n/2+0.5:1:n/2-0.5)/n; % range for grid (from R=0 to R=1)
Y=2*rmax*(-n/2+0.5:1:n/2-0.5)/n; % range for grid (from R=0 to R=1)
[xm,ym]=meshgrid(X,Y); % x-y coordinates for range of grid
R= sqrt(xm.^2 + ym.^2); % Normalized radius vector
rando=randn(145,145); % random phase initialization
imgA = imread('void.jpg');
imgB = imread('void2.jpg');
%Convert source image to Grayscale
imgA = rgb2gray(imgA);
imgB = rgb2gray(imgB);
figure; imshow(imgA); title('Grayscale ImageA');
figure; imshow(imgB); title('Grayscale ImageB');
%Get the size of the source image
[rowsSource, colsSource, numberOfColorChannelsSource] = size(imgA);
%Get the size of image B
[rowsTarget, colsTarget, numberOfColorChannelsTarget] = size(imgB);
%Check if lateral sizes match
if rowsimgB ~= rowsimgA || colsimgA ~= colsimgB
imgB = imresize(imgB, [rowsimgA colsimgA]);
end
%Convert images to double
imgA = im2double(imgA);
imgB = im2double(imgB);
%% Source plane to target plane
A = abs(imgA).*exp(1*(1i*rando*pi)); % source amplitude (captured on camera) with random source phase = reconstructed source mode
A=A./max(max(A));

Accepted Answer

madhan ravi
madhan ravi on 9 Jul 2020
Edited: madhan ravi on 9 Jul 2020
rando = randn(size(imgA)); % random phase initialization, put this line after imgA = ...
size(imgA) should be be equal to size(rando) to be compatible with matrix or array vs matrix multiplication
  4 Comments
Soong Wei Kang
Soong Wei Kang on 9 Jul 2020
Hi sir, I have received another error as shown in the attach file.
madhan ravi
madhan ravi on 9 Jul 2020
rando = randn(size(imgA)); % ^ missed it by mistake

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!