How can I convert categorical variable to continuous variable in MATLAB?
8 views (last 30 days)
Show older comments
Anslem Ezewuzie
on 31 Oct 2021
Commented: Star Strider
on 31 Oct 2021
Date Open High Low Close Adj Close Volume
19/4/2013 6.5 6.56 6.38 6.5 5.312031 41720121
22/4/2013 6.64 6.64 6.5 6.64 5.426445 19625589
23/4/2013 6.64 6.64 6.64 6.64 5.426445 0
24/4/2013 6.78 6.82 6.72 6.78 5.540857 34039327
25/4/2013 6.84 6.86 6.76 6.84 5.589892 25746865
26/4/2013 6.8 6.86 6.74 6.8 5.557202 15952507
29/4/2013 6.84 6.84 6.76 6.84 5.589892 12462006
0 Comments
Accepted Answer
Star Strider
on 31 Oct 2021
I am not certain which are the categorical variables.
The variable names can be referred to as elements of the cell array that contains them, and the dates can be converted to datetime varialbes, that are essentially continous variables (and can be made numeric with the datenum funciton if necessary) —
C = {'19/4/2013' 6.5 6.56 6.38 6.5 5.312031 41720121
'22/4/2013' 6.64 6.64 6.5 6.64 5.426445 19625589
'23/4/2013' 6.64 6.64 6.64 6.64 5.426445 0
'24/4/2013' 6.78 6.82 6.72 6.78 5.540857 34039327
'25/4/2013' 6.84 6.86 6.76 6.84 5.589892 25746865
'26/4/2013' 6.8 6.86 6.74 6.8 5.557202 15952507
'29/4/2013' 6.84 6.84 6.76 6.84 5.589892 12462006 };
T1 = cell2table(C, 'VariableNames',{'Date','Open','High','Low','Close','Adj Close','Volume'})
H = T1.Properties.VariableNames{3}
T1.Date = datetime(T1.Date,'InputFormat','dd/MM/yyyy')
numericalDates = datenum(T1.Date)
Esperiment to get the desired result.
.
0 Comments
More Answers (1)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!