Error using vertcat Dimensions of arrays being concatenated are not consistent.

1 次查看(过去 30 天)
Please I humbly ask for help on the below error in my code.
Error in LenaPhase (line 428)
ShowPro=[ShowProA;zeros(4576*5+40*4);ShowProB];
% Simulated Projections
if(ShowData)
ShowPro=[ShowProA;ones(4576*5+40*4);ShowProB];
figure(2); set(gcf,'color','white');
imshow(ShowPro,[]);
% Reconstructed phase map
ShowPhases=[ShowPhaseA;zeros(40,576*5+40*4);ShowPhaseB];
figure(3); set(gcf,'color','white');
imshow(-ShowPhases,[]);
end

回答(2 个)

Yussif M. Awelisah
Sorry for the late response.
Please the full code is attached.
  2 个评论
Walter Roberson
Walter Roberson 2020-5-2
Well when you stop at that line, you will find that the matrix sizes are not even close to being equal to permit the [;] horzcat operation.
for i = 1:length(E)
% transmision function T(x,y), equation 4
transmission = exp(-thickness*(mu/2+1i*k*delta));
% kernal function of propagation, equation 11
propagator = exp(-1i*pi*z*lambda*w2);
% phase contrast image
img0 = abs(ifft2(fft2(transmission).*propagator).^2);
% scaling of current energy in spectrum
scaling = spectrum*dx*dy/R1^2*exposureTime*E*gain;
% summary
projection = projection + img0*scaling;
% noise variance
noiseVariance = noiseVariance + img0*scaling*E*gain;
end
You loop over i, but your calculation does not involve i anywhere. You loop to length(E) suggesting that you plan to use i to index E, but you do not do that. You calculate the same thing every time except that you are adding copies of the same values into projection and noiseVariance.
I would suggest to you that in lines such as
scaling = spectrum*dx*dy/R1^2*exposureTime*E*gain;
that you wanted to index E by i, E(i)
Walter Roberson
Walter Roberson 2020-5-2
Your code has too many "magic numbers"
ShowPro=[ShowProA;ones(4576*5+40*4);ShowProB];
figure(2); set(gcf,'color','white');
imshow(ShowPro,[]);
% Reconstructed phase map
ShowPhases=[ShowPhaseA;zeros(40,576*5+40*4);ShowPhaseB];
Note that ones(4576*5+40*4) is asking for a 23040 x 23040 array of ones.
When we compare against the later zeros(40,576*5+40*4) we might suspect that the 4576*5+40*4 version is missing a "0,".
Be careful about whether you are wanting to concatenate by row or by column.

请先登录,再进行评论。


Yussif M. Awelisah
I am grateful for your time and contribution.
so please what solution do you suggest for this error.
  1 个评论
Walter Roberson
Walter Roberson 2020-5-4
Every place that you have a hard-coded size, replace it with a variable or a size() or an expression based those things in obvious ways (and multiplying by 5 and adding 40*4 is not an obvious way!). This will make it much clearer what sizes of arrays are, and make it easier for you to figure out what size of padding you need in places.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by