Importing from XLSX file, column dates, column data

Hello,
I am new to Matlab and I want to test the MACD rule on a dataset.
I downloaded the data into Excel and imported the data into Matlab
The first column gives the dates, ranging from 01-Jan-1990 to 18-May-2012. i changed these dates to numeric data in excel and then applied the following command in Matlab:
x = xlsread('x.xlsx')
Date(:,datecol) = Date(:,datecol) + datenum('30-Dec-1899');
D = datestr(x(:,1))
Now the problem is that Matlab creates a seperate variable containing the dates and this variable is an (ab) variable, but this type of variable is strange because i caanot plot it in combination with the share prices. how do I get the dates in a variable that i can work with?
Thanks in advance,

3 件のコメント

Oleg Komarov
Oleg Komarov 2012 年 5 月 27 日
You mean it's a char variable?
Jelle
Jelle 2012 年 5 月 27 日
I am not sure what a char variable is but in the workspace there is an 'ab' in the yellow box in front of the variable name. I think its like the answer (ans) variable that matlab computes automatically
Oleg Komarov
Oleg Komarov 2012 年 5 月 27 日
You can right-click on the column headings of the workspace pane and select the voice 'Class'. It will tell which class the variable belongs to.

サインインしてコメントする。

回答 (1 件)

Oleg Komarov
Oleg Komarov 2012 年 5 月 27 日

0 投票

Keep the dates in double format, then plot then call datetick()

5 件のコメント

Jelle
Jelle 2012 年 5 月 27 日
Ok this seems to work indeed to plot the dates on the x-axis but would it not be simpler if both dates and data is in one file, or that dates are a workable variable instead of this 'ab' variable
Jelle
Jelle 2012 年 5 月 27 日
Now i used the syntax:
startdate = datenum('01-Jan-1990')
endDate = datenum('18-May-2012')
xData = linspace(startdate, endDate,12);
plot(DJ)
set(gca,'XTickLabel',DJ)
datetick('x','mm/dd/yy','keepticks')
But the x axis starts at 01/00/00 and ends at 06/04/2016. This seems strange...
Oleg Komarov
Oleg Komarov 2012 年 5 月 27 日
You can keep dates and data in one 'file' (do you mean variable?) as long as their types are consistent.
To be very intuitive, numbers are generally class double, while strings are generally class char.
You cannot have words mixed with numbers, therefore to keep them together dates should be stored as serial numbers.
What is DJ?
Note that to be able to specify the x-values you have to use the syntax
plot(x,y)
where x should be your xData.
Jelle
Jelle 2012 年 5 月 27 日
Ok that is clear, so i keep the dates in a seperate variable shown as numerical data. DJ is the dowjones containg prices of the dow jones from 01-01-1990 to 18-05-2012, so I used DJ instead of xData.
I now have a seperate variable named 'dates' containing all the days (in numerical form) from Jan 1990 untill May 2012
Oleg Komarov
Oleg Komarov 2012 年 5 月 27 日
Then you should just call:
plot(dates, DJ)
datetick()

サインインしてコメントする。

質問済み:

2012 年 5 月 27 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by