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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by