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

1 view (last 30 days)
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

Answers (2)

Yussif M. Awelisah
Yussif M. Awelisah on 2 May 2020
Sorry for the late response.
Please the full code is attached.
  2 Comments
Walter Roberson
Walter Roberson on 2 May 2020
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 on 2 May 2020
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.

Sign in to comment.


Yussif M. Awelisah
Yussif M. Awelisah on 4 May 2020
I am grateful for your time and contribution.
so please what solution do you suggest for this error.
  1 Comment
Walter Roberson
Walter Roberson on 4 May 2020
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.

Sign in to comment.

Categories

Find more on Matrices and Arrays 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!