필터 지우기
필터 지우기

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
Yussif M. Awelisah 2020년 5월 2일
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
Yussif M. Awelisah 2020년 5월 4일
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