Convert 2D into 3D matrix

30 ビュー (過去 30 日間)
Dina Trajkovska
Dina Trajkovska 2016 年 8 月 16 日
回答済み: KSSV 2016 年 8 月 16 日
Hey everyone,
I need to convert a 2D into a 3D matrix. The initial dimensions are nx64 (the first number is always random) and it needs to be transformed into 4x16xn, but in this order:
1 5 9 13 17 ... 61
2 6 10 14 18 ... 62
3 7 11 15 19 ... 63
4 8 12 16 20 ... 64
and
1 2 3 4 5 ... 16
17 18 19 20 21 ... 32
33 34 35 36 37 ... 48
49 50 51 52 53 ... 64
The third dimension should be the n rows from the original matrix. Can someone help me with both cases?

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 16 日
編集済み: Azzi Abdelmalek 2016 年 8 月 16 日
reshape(A(:),16,[])'

KSSV
KSSV 2016 年 8 月 16 日
You can use reshape to convert 2D matrix into 3D. But remember that the number of elements should not vary.
clc; clear all;
d = 1:64 ;
% 2D matrix
d2D = reshape(d,4,[]) ; % let the MATLAB decide the number of columns
% 2D to 3D
d3D = reshape(d2D,4,8,[]);
% fix the number of rows and columns and let matlab decide the number of matrices in 3D

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by