MATLAB Answers

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

1 view (last 30 days)
Yussif M. Awelisah on 27 Apr 2020
Commented: Walter Roberson on 4 May 2020
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 CommentShowHide None
Walter Roberson on 27 Apr 2020
You did not tell us sizee(ShowProdA) or size(ShowProdB)

Sign in to comment.

Answers (2)

Yussif M. Awelisah on 2 May 2020
Sorry for the late response.
Please the full code is attached.
2 CommentsShowHide 1 older comment
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 on 4 May 2020
I am grateful for your time and contribution.
so please what solution do you suggest for this error.
1 CommentShowHide None
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.

Community Treasure Hunt

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

Start Hunting!