how to separate a matrix according to class labels?

조회 수: 4 (최근 30일)
Ararat Cetinkaya
Ararat Cetinkaya 2020년 3월 7일
답변: Guillaume 2020년 3월 7일
Hi everybody,
I have a matrix with size of 1500x3. Third column of the this matrix contains the class labes as a numeric like 3,2,1 and size of the each classes is uncertain. I want to divide the main matrix into three different matrices according to these three different classes. Only elements from class 1 will be taken in the first matrix, Only elements from class 2 will be taken in the second matrix, Only elements from class 3 will be taken in the third matrix.

답변 (1개)

Guillaume
Guillaume 2020년 3월 7일
classmatrices = splitapply(@(rows) {yourmatrix(rows, :)}, (1:size(yourmatrix, 1)'), yourmatrix(:, 3))
is one way. Note that in matlab it's rarely useful to do this splitting. It's often easier to work on the whole 1500x3 matrix and use aggregation functions such as groupsummary.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by