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

2 次查看(过去 30 天)
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.

采纳的回答

Rik
Rik 2018-6-1
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by