How can I convert categorical variable to continuous variable in MATLAB?

8 views (last 30 days)
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

Accepted Answer

Star Strider
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'})
T1 = 7×7 table
Date Open High Low Close Adj Close Volume _____________ ____ ____ ____ _____ _________ __________ {'19/4/2013'} 6.5 6.56 6.38 6.5 5.312 4.172e+07 {'22/4/2013'} 6.64 6.64 6.5 6.64 5.4264 1.9626e+07 {'23/4/2013'} 6.64 6.64 6.64 6.64 5.4264 0 {'24/4/2013'} 6.78 6.82 6.72 6.78 5.5409 3.4039e+07 {'25/4/2013'} 6.84 6.86 6.76 6.84 5.5899 2.5747e+07 {'26/4/2013'} 6.8 6.86 6.74 6.8 5.5572 1.5953e+07 {'29/4/2013'} 6.84 6.84 6.76 6.84 5.5899 1.2462e+07
H = T1.Properties.VariableNames{3}
H = 'High'
T1.Date = datetime(T1.Date,'InputFormat','dd/MM/yyyy')
T1 = 7×7 table
Date Open High Low Close Adj Close Volume ___________ ____ ____ ____ _____ _________ __________ 19-Apr-2013 6.5 6.56 6.38 6.5 5.312 4.172e+07 22-Apr-2013 6.64 6.64 6.5 6.64 5.4264 1.9626e+07 23-Apr-2013 6.64 6.64 6.64 6.64 5.4264 0 24-Apr-2013 6.78 6.82 6.72 6.78 5.5409 3.4039e+07 25-Apr-2013 6.84 6.86 6.76 6.84 5.5899 2.5747e+07 26-Apr-2013 6.8 6.86 6.74 6.8 5.5572 1.5953e+07 29-Apr-2013 6.84 6.84 6.76 6.84 5.5899 1.2462e+07
numericalDates = datenum(T1.Date)
numericalDates = 7×1
735343 735346 735347 735348 735349 735350 735353
Esperiment to get the desired result.
.

More Answers (1)

Anslem Ezewuzie
Anslem Ezewuzie on 31 Oct 2021
Helpful. Thank you very much Star Strider.

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!