Borrar filtros
Borrar filtros

Dividing a Matrix into submatrices according to a specific column value

14 visualizaciones (últimos 30 días)
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?
Thank you in advance.

Respuesta aceptada

rakbar
rakbar el 10 de En. de 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);

Más respuestas (1)

Akira Agata
Akira Agata el 10 de En. de 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

Categorías

Más información sobre Time Series 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!

Translated by