Conversion of Categorical to double
조회 수: 94 (최근 30일)
이전 댓글 표시
Hello everyone'
I have a table with values created with a categorization that I do not know. I would like to convert these into double array for normal manipulation. However, the following code gives me a categorical array that cannot be manaipulated easily by normal operations.
y=table2array(Data(:,1));
Converting it into a double, it yield values that are not the same as what is contained in the table.
y1=grp2idx(y);
Can someone please explain what the vector y1 represents and how I can use that to get the double array that is not categorical.
thanks.
댓글 수: 0
채택된 답변
dpb
2019년 5월 1일
편집: dpb
2019년 5월 1일
y1 is a grouping variable of which bin each refers to; it will be in the range of 1:N where N is number of unique categories in the categorical variable (not all of which may be present in a subset of the original).
Just
v=double(Data(:,1));
will reproduce the underlying values of the categorical array.
But, what do you want to do with a categorical array that you can't seem to do as its existing type? One would presume it was created as categorical for a reason.
댓글 수: 2
dpb
2019년 5월 1일
How was that .mat file created to turn Column7 variable into categorical? I'd suggest going back to that step and fix your problem there--it does appear that those should have been doubles all along.
추가 답변 (1개)
dpb
2019년 5월 1일
To answer the question posed,
Data.Column7=double(Data.Column7);
but see the comment above -- the better solution would be to fix the problem at the point it was created instead of cleaning up a mess later.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!