# Dividing a Matrix into submatrices according to a specific column value

8 vues (au cours des 30 derniers jours)
Michail Isaakidis le 10 Jan 2019
Hi all!
So I have a very big matrix (10000x6 elements) with all my data and one of the columns contains the group that each set of data belongs (from 1 to 500). How would it be possible to seperate them with into individual matrices with the use of the group number?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

rakbar le 10 Jan 2019
Use MATLAB findgroup and splitapply functions. Here is an example:
https://www.mathworks.com/help/matlab/ref/splitapply.html#bux2_9d
% create a random matrix 10 x 4
A = rand(10,4);
% the 5th column is the "Gourp" column
A(:,5) = [ 1 1 2 2 3 3 4 4 5 5 ];
% Find the "Grouping" vector
G = findgroups(A(:,5));
% function to return gourped sum matrix
func = @(x){(x)};
% return each submatrix (cell array)
Y = splitapply(func,A,G);
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Michail Isaakidis le 11 Jan 2019
Thank you very much! That solved my problem!

Connectez-vous pour commenter.

### Plus de réponses (1)

Akira Agata le 10 Jan 2019
The following is an another way that is easy to understand intuitively:
% create a random matrix 10 x 4
A = rand(10,4);
% the 5th column is the "Gourp" column
A(:,5) = [ 1 1 2 2 3 3 4 4 5 5 ];
% Find unique values
ID = unique(A(:,5));
% Separate the matrix
Y = cell(size(ID));
for kk = 1:numel(ID)
idx = A(:,5) == ID(kk);
Y{kk} = A(idx,:);
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Time Series dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by