How to divide a matrix into smaller matrices
69 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (4)
Jurgen
el 29 de Abr. de 2015
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 comentarios
Guillaume
el 29 de Abr. de 2015
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 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!