How to divide a matrix into smaller matrices
조회 수: 69 (최근 30일)
이전 댓글 표시
I need to split up a 2x10,000 matrix into 40 matrices with 500 elements in each matrix. Also the 2x10,000 matrix is loaded from an excel file and the values should be kept in order. I've seen other people with this similar problem but they have random numbers in their matrices whereas i'm trying to keep them in their place. For example i want values 1-500 in the first one and so on in the order they are in from the original matrix.
댓글 수: 0
답변 (4개)
Jurgen
2015년 4월 29일
A cell type can hold several matrices, so splitting your matrix should output a cell. Mat2cell has syntax that let's you carve up your matrix into any subshapes.
If the syntax is hard you might try downloading a user contributed function/file from the file exchange.
댓글 수: 0
Guillaume
2015년 4월 29일
It's really not complicated. As others have said use mat2cell. The dimNdist arguments of mat2cell says how many rows, columns, pages, etc. go into each matrix.
For example, let's split your matrix into 40 along the columns and keep the 2 rows together:
m = rand([2 10000]); %for demo, replace with your own matrix
coldist = size(m, 2) / 40 * ones(1, 40); %split the number of columns by 40 and replicate 40 times.
splitmats = mat2cell(m, 2, coldist)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!