Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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

Respuestas (2)

Yussif M. Awelisah
Yussif M. Awelisah el 2 de Mayo de 2020
Sorry for the late response.
Please the full code is attached.
  2 comentarios
Walter Roberson
Walter Roberson el 2 de Mayo de 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 el 2 de Mayo de 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.

Iniciar sesión para comentar.


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

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by