Assign a categorical value to a table
조회 수: 4 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Classification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!