Matrix dimensions must agree.

조회 수: 11 (최근 30일)
Soong Wei Kang
Soong Wei Kang 2020년 7월 9일
댓글: madhan ravi 2020년 7월 9일
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));

채택된 답변

madhan ravi
madhan ravi 2020년 7월 9일
편집: madhan ravi 2020년 7월 9일
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
Soong Wei Kang
Soong Wei Kang 2020년 7월 9일
Hi sir, I have received another error as shown in the attach file.
madhan ravi
madhan ravi 2020년 7월 9일
rando = randn(size(imgA)); % ^ missed it by mistake

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by