Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Excel date column export into Matlab

  1. Sep 17, 2013 #1
    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. jcsd
  3. Sep 17, 2013 #2

    kreil

    User Avatar
    Gold Member

  4. Sep 17, 2013 #3

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    As a workaround, what happens if you add an empty column in the spreadsheet?
     
  5. Sep 18, 2013 #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
     
  6. Sep 19, 2013 #5

    kreil

    User Avatar
    Gold Member

    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 (Text):

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

    d =

          693960

    >> datestr(d)

    ans =

    30-Dec-1899
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Excel date column export into Matlab
Loading...