Clear Filters
Clear Filters

How to divide a matrix into smaller matrices

68 views (last 30 days)
Juan Fidalgo
Juan Fidalgo on 29 Apr 2015
Answered: Guillaume on 29 Apr 2015
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.

Answers (4)

Ken Atwell
Ken Atwell on 29 Apr 2015

Juan Fidalgo
Juan Fidalgo on 29 Apr 2015
i did'nt really understand that answer. Could you explain the process?

Jurgen on 29 Apr 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.

Guillaume on 29 Apr 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)


Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!