Reshaping a matrix in particular order

1 回表示 (過去 30 日間)
Mahmood Azhar Qureshi
Mahmood Azhar Qureshi 2021 年 3 月 31 日
回答済み: darova 2021 年 4 月 1 日
Hi, I have a random size matrix with rows a multiple of 7 and columns a multiple of 4. (e.g. 14x8, 28x12). I want to reshape the matrix into a 7x4xn matrix with additional values going into a third (n) dimension (e.g. 14x8 becomes 7x4x4). I know how to use reshape but it changes the order in which i want to generate the 3D matrix. As an example consider:
A = [1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16]
% gives a 4x4 matrix like
% A = 1 2 3 4
% 5 6 7 8
% 9 10 11 12
% 13 14 15 16
%reshape(A,2,2,[]) gives
ans(:,:,1) = [1 9
5 13]
ans(:,:,2) = [2 10
6 14]
ans(:,:,3) = [3 11
7 15]
ans(:,:,4) = [4 12
8 16]
% I want to have something like this
ans(:,:,1) = [1 2
5 6]
ans(:,:,2) = [9 10
13 14]
ans(:,:,3) = [3 4
7 8]
ans(:,:,4) = [11 12
15 16]

回答 (1 件)

darova
darova 2021 年 4 月 1 日

カテゴリ

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