Excel date column export into Matlab

  • #1
20
0
Hi everybody,
I need assistance. I have excel file that conntains a date column and another column. I wish to plot the date on x-axis and the second column on y axis. I wrote the MATLAB code below.

This is my code. data=xlsread('DataTest','Sheet1'); q=data(:,2); time=data(:,1);

Error message

Attempted to access data(:,2); index out of bounds because size(data)=[193,1].

Matlab is not reading the first column of the excel file that contains the date so it takes the second column as the first column as a result it could not find second column. Please help
 
  • #2
http://www.mathworks.com/help/matlab/import_export/when-to-convert-dates-from-excel-files.html
 
  • #3
As a workaround, what happens if you add an empty column in the spreadsheet?
 
  • #4
Thanks Kreil,
I have succeeded in using datenum. See the code below
wt=xlsread('DataTest','sheet1');
datecol = 1; wt(:,datecol) = wt(:,datecol) + datenum('30-Dec-1899'); x=wt(:,1); qo=wt(:,2); plot(x,qo);

How do I use datetick to get the x (date axis) in day-month-year ('dd-mmm-yyyy') format?
Thanks Isa
 
  • #5
datetick is a function for adding the date to tick labels on a plot.

Use the datestr() function to reverse what datenum() does. For example,

Code:
>> d = datenum('30-Dec-1899')

d =

      693960

>> datestr(d)

ans =

30-Dec-1899
 

Suggested for: Excel date column export into Matlab

Replies
4
Views
491
Replies
1
Views
628
Replies
4
Views
915
Replies
6
Views
734
Replies
5
Views
1K
Replies
2
Views
1K
Replies
32
Views
1K
Replies
2
Views
966
Replies
2
Views
1K
Back
Top