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
1 件のコメント
回答 (2 件)
Yussif M. Awelisah
2020 年 5 月 2 日
2 件のコメント
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
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
2020 年 5 月 4 日
1 件のコメント
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 Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!