필터 지우기
필터 지우기

Assign a categorical value to a table

조회 수: 4 (최근 30일)
Sarah DS
Sarah DS 2022년 5월 4일
댓글: Sarah DS 2022년 5월 4일
Hello, Matlab community. I have a table that has 60 rows and 4 columns. The table is a feature extraction table to be fed into a classifier. My question is, how do I assign categorical values to the first 30 rows of the table? Let's say "Running", from the 31 to 41 "Walking", from the row 41 to 51 "Upstairs" and "downstairs from the row 51 to 60. At the moment, I assume I can't put this table into the KNN classifier because It does not have any separate categories. It is just a massive table with no categories.
I have tried using the categorical function; however, it just assigns a name to the categories, not the range from where they go in the feature table.

채택된 답변

dpb
dpb 2022년 5월 4일
N=[30,10,10,10]; % the number of the four categories each
C=["Running";"Walking","Upstairs","Downstairs"]; % the categories
tmp=arrayfun(@(c,n)repmat(c,n,1),C,N,'UniformOutput',false); % build the sets
tYourTable.Categories=categorical(vertcat(tmp{:})); % and add the categories variable
One would presume there's some other variable inside the table from which the condition could be deduced, however, in which case one could use that logical condition from which to build the categories without the need to manually assign the counts.
  댓글 수: 1
Sarah DS
Sarah DS 2022년 5월 4일
Thank you Sir! Much appreciated

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by