MAT2TILES: divide array into equal-sized sub-arrays

버전 1.0.0.0 (2.76 KB) 작성자: Matt J
Splits an array of any dimension into cell array of equal sized chunks.
다운로드 수: 3.5K
업데이트 날짜: 2017/9/24

라이선스 보기

MAT2TILES is basically a wrapper for mat2cell but with a more convenient interface when you are simply trying to decompose an N-dimensional array into equal-sized chunks. It takes the desired chunk-size as an input argument, whereas mat2cell does not. MAT2TILES also has some convenient shortcuts for when you only want to tile along particular dimensions (see below).
USAGE:

C=mat2tiles(X,D1,D2,D3,...,Dn)
C=mat2tiles(X,[D1,D2,D3,...,Dn])

will produce a cell array C containing adjacent chunks of the array X, with each chunk of dimensions D1xD2xD3x...xDn. If a dimension Di does not divide evenly into size(X,i), then the chunks at the upper boundary of X along dimension i will be truncated.

It is permissible for the Di to be given value Inf. When this is done, it is equivalent to setting Di=size(X,i). This is useful if you want to tile along only certain array dimensions.

EXAMPLE 1: Split a 28x28 matrix into 4x7 sub-matrices

>> A=rand(28); C=mat2tiles(A,[4,7])

C =

[4x7 double] [4x7 double] [4x7 double] [4x7 double]
[4x7 double] [4x7 double] [4x7 double] [4x7 double]
[4x7 double] [4x7 double] [4x7 double] [4x7 double]
[4x7 double] [4x7 double] [4x7 double] [4x7 double]
[4x7 double] [4x7 double] [4x7 double] [4x7 double]
[4x7 double] [4x7 double] [4x7 double] [4x7 double]
[4x7 double] [4x7 double] [4x7 double] [4x7 double]

EXAMPLE 2: Split a 20x20x6 array into 20x6x3 sub-arrays. This example
illustrates how 'Inf' can be used to indicate that one of the sub-array
dimensions is to be the same as in the original array, in this case size(A,1)=20.


>> A=rand(20,20,6);

>> C=mat2tiles(A,[Inf,6,3]) %equivalent to mat2tiles(A,[20,6,3])

C(:,:,1) =

[20x6x3 double] [20x6x3 double] [20x6x3 double] [20x2x3 double]


C(:,:,2) =

[20x6x3 double] [20x6x3 double] [20x6x3 double] [20x2x3 double]

The example also shows a situation where the original array does not
divide evenly into sub-arrays of the specified size. Note therefore that
some boundary sub-chunks are 20x2x3.

인용 양식

Matt J (2024). MAT2TILES: divide array into equal-sized sub-arrays (https://www.mathworks.com/matlabcentral/fileexchange/35085-mat2tiles-divide-array-into-equal-sized-sub-arrays), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2011b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0

Added examples to help documentation.
Edit title