MATLAB Answers

Translated by

이 페이지의 내용은 영어에서 자동 번역되었습니다. 자동 번역 기능을 해제하려면 "<a class="turn_off_mt" href="#">여기</a>"를 클릭하십시오.


Conversion of Categorical to double

Asked by Lui
on 1 May 2019
Latest activity Edited by Lui
on 1 May 2019
Accepted Answer by dpb
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.
Converting it into a double, it yield values that are not the same as what is contained in the table.
Can someone please explain what the vector y1 represents and how I can use that to get the double array that is not categorical.


Sign in to comment.

2 Answers

Answer by dpb
on 1 May 2019
Edited by dpb
on 1 May 2019
 Accepted Answer

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).
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.


I have attached a table below. The table created as categorical. I need to create an array that can be multiplied or divided etc.
Data_1=table2array(Data(:,1)); % this gives me the catrogorical array
% this array cannot be multilied by a factor as a double array
v=double(Data_1(:,1)); % this gives me the unique categories
How do I retrieve a double array from the table which has categories so that I can have the same values as what is in the table but not categorical.
How do I carry out a simple arithmetic operation like multiplcation on the categorical array? And can it be converted to a double array.
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.

Sign in to comment.

Answer by dpb
on 1 May 2019

To answer the question posed,
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.


Thank you for the guidance. I have resolved it from the initial file. I did convert the excel file to string while importing it to matlab. Then I cahnged the file into a double.This excluded the categorical part. I appreciate.

Sign in to comment.

Translated by