How to insert a column of zero into a 3D matrix?

9 views (last 30 days)
A = rand(128,256,36);
B = zeros(128,1);
I would like to concatenate B and A so that C = cat(2,B,A(:,:,1) but for every A(:,:,1), A(:,:,2), ... A(:,:,3).
How can I do this, instead of doing it manually?

Accepted Answer

Simon Chan
Simon Chan on 30 Mar 2022
Try this
C=cat(2,A,repmat(B,1,1,size(A,3)));

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!