concatenate vertically along the 3rd dimension of a matrix

39 ビュー (過去 30 日間)
Varshini Guddanti
Varshini Guddanti 2016 年 7 月 14 日
コメント済み: piyush kant 2022 年 7 月 15 日
I have a matrix which has these 3rd dimensions. A(:,:,1), A(:,:,2), A(:,:,3)
Now, I wanted these three to be vertically concatenated .
I know this: vertcat(A(:,:,1), A(:,:,2), A(:,:,3));
I wanted to know other solutions as the no.of 3rd dimensions seem to change for every loop.
Thanks

回答 (3 件)

Guillaume
Guillaume 2016 年 7 月 14 日
splitA = num2cell(A, [1 2]); %split A keeping dimension 1 and 2 intact
vertcat(splitA{:})
  2 件のコメント
Varshini Guddanti
Varshini Guddanti 2016 年 7 月 14 日
Thanks for the reply!
mario alejandro
mario alejandro 2019 年 5 月 7 日
thanks! you are the best

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2016 年 7 月 14 日
reshape(permute(A,[2,1,3]),size(A,2),[])'
  4 件のコメント
Mariana
Mariana 2017 年 11 月 22 日
What about with a generic number n of matrices
piyush kant
piyush kant 2022 年 7 月 15 日
reshape(permute(A,[1,3,2]),[],size(A,2))

サインインしてコメントする。


Image Analyst
Image Analyst 2016 年 7 月 14 日
Not sure what you mean by saying you have a matrix with these planes along the third dimension A(:,:,1), A(:,:,2), A(:,:,3)? They are already along the third dimension. For example they could be the red, green, and blue color channels of an RGB image. To concatenate 2d arrays along the third dimension, so
array3d = cat(3, array2da, array2db, array2dc, array2dc, .....);
for as many 2D arrays as you have.
  2 件のコメント
Varshini Guddanti
Varshini Guddanti 2016 年 7 月 14 日
編集済み: Varshini Guddanti 2016 年 7 月 14 日
Yeah, I want to concatenate the third dimensions vertically to display a figure.
Previously, I had done it using vertcat and cat but I donot want it to be done manually, but, I want to concatenate each 3rd dimension matrix generated in a loop to be concatenated vertically.
Image Analyst
Image Analyst 2016 年 7 月 14 日
Explain why vercat and cat are manual and a for loop is not manual.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by