chunkify

버전 1.0.0.0 (851 Bytes) 작성자: Gerald Dalley
Splits a vector or cell array into evenly-sized chunks.
다운로드 수: 1.9K
업데이트 날짜: 2006/2/21

라이선스 없음

C = CHUNKIFY(DATA, CHUNKSIZE)

Turns a matrix DATA into chunks of data with CHUNKSIZE elements in each cell entry of C. If DATA's size is not evenly divisible by CHUNKSIZE, the last entry in C will contain fewer items.

Examples:

chunkify([1 2 3 4], 2) --> {[1 2] [3 4]}
chunkify([1 2 3 4 5], 2) --> {[1 2] [3 4] [5]}

chunkify({'1' '2' '3' '4'}, 2) --> {{'1' '2'} {'3' '4'}}

Motivating scenario:

I wrote this function because I needed to process a lot of data in separate chunks, sometimes to have different machines run each chunk, sometimes to just load in chunks of the data files so I could balance I/O and memory constraints. In both these cases, I found it handy to have this simple function to break up my index vector. Because the number of data items was not always an exact multiple of my desired chunk size, I used this function instead of Matlab's built-in RESHAPE (putting one chunk per row, for example).

TODO:
If DATA is multi-dimensional, the dimension on which to chunkify is given by DIM.
chunkify([1 2 3 4], 2, 2) --> {[1 2] [3 4]}
chunkify([1 2 3 4], 2, 1) --> {[1 2 3 4]}
chunkify([1 2; 3 4], 2, 1) --> {[1 2] [3 4]}

인용 양식

Gerald Dalley (2024). chunkify (https://www.mathworks.com/matlabcentral/fileexchange/10004-chunkify), MATLAB Central File Exchange. 검색됨 .

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

Community Treasure Hunt

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

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

Removed boilerplate copyright, added motivating example.