필터 지우기
필터 지우기

Dividing a Matrix into submatrices according to a specific column value

조회 수: 14 (최근 30일)
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.

채택된 답변

rakbar
rakbar 2019년 1월 10일
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개)

Akira Agata
Akira Agata 2019년 1월 10일
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

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by