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.

回答(4 个)

Ken Atwell
Ken Atwell 2015-4-29

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

Jurgen
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.

Guillaume
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)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by