How to divide a matrix into smaller matrices

64 ビュー (過去 30 日間)
Juan Fidalgo
Juan Fidalgo 2015 年 4 月 29 日
回答済み: Guillaume 2015 年 4 月 29 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by