Excel date column export into Matlab

  • MATLAB
  • Thread starter adeeyo
  • Start date
  • #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
 

Answers and Replies

  • #3
35,258
11,510
As a workaround, what happens if you add an empty column in the spreadsheet?
 
  • #4
20
0
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
kreil
Insights Author
Gold Member
668
67
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
 

Related Threads on Excel date column export into Matlab

Replies
3
Views
27K
Replies
2
Views
912
Replies
2
Views
3K
Replies
2
Views
7K
Replies
2
Views
2K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
2
Views
2K
  • Last Post
2
Replies
31
Views
3K
  • Last Post
Replies
18
Views
3K
  • Last Post
Replies
6
Views
2K
Top