Adding a second layer to a 2D matrix

I have having issues with trying to figure out how to add a second layer to a 2d matrix. I created a 4x4 matrix of random integers from -10 to 10. Now I have to add a second layer to the matrix so that it is 4x4x2. The new layer needs to be all zeros and it has to be done within one line of code. I have tried several things but nothing seems to work. Thanks in advance!

 採用された回答

Image Analyst
Image Analyst 2017 年 4 月 16 日

0 投票

Try cat(3,...)
newMatrix = cat(3, old2DMatrix, second2DLayer); % Will be 4x4x2
Use your own variable names, needless to say.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

タグ

質問済み:

2017 年 4 月 16 日

回答済み:

2017 年 4 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by