Clear Filters
Clear Filters

How can i add a 2D matrix of zeros on top of a 3D matrix of logicals

2 views (last 30 days)
Hi,
I've subtracted the bottom z values of a 3D matrix (ffilter) and now i want to add a 2D matrix in the z direction on top, to create a new matrix (ffilter2).
if true
ffilter2=ffilter2(:,:,(1:617));
[N,v,b]=size(ffilter2)
c=zeros(N,v,1);
ffilter2=ffilter2(:,:,(c:618));
end
I have a 2D matrix of zeros (size = x_of3D_matrix;y_of3D_matrix,1). And I want to "add" this to the 3D matrix so this will result in an 3D matrix with an extra layer (of zeros) in the z direction (on top). I probably didn't formulate this the proper way. But I hope somebody understands what I'm asking. All the help is really appreciated!
Thank you.

Accepted Answer

Rik
Rik on 1 Jun 2018
You can use the cat function:
ffilter2=ffilter2(:,:,(1:617));
[N,v,b]=size(ffilter2)
c=zeros(N,v,1,'like',ffilter2);%or c=false(N,v,1);
ffilter2=cat(3,ffilter2,c);

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!