Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7925735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:25:56+00:00 2026-06-03T18:25:56+00:00

I have a dataset for which I have extracted the date at which an

  • 0

I have a dataset for which I have extracted the date at which an event occurred. The date is in the format of MMDDYY although MatLab does not show leading zeros so often it’s MDDYY.

Is there a method to find the mean or median (I could use either) date? median works fine when there is an odd number of days but for even numbers I believe it is averaging the two middle ones which doesn’t produce sensible values. I’ve been trying to convert the dates to a MatLab format with regexp and put it back together but I haven’t gotten it to work. Thanks

dates=[32381 41081  40581  32381  32981 41081   40981  40581];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:25:59+00:00Added an answer on June 3, 2026 at 6:25 pm

    You can use datenum to convert dates to a serial date number (1 at 01/01/0000, 2 at 02/01/0000, 367 at 01/01/0001, etc.):

    strDate='27112011';
    numDate = datenum(strDate,'ddmmyyyy')
    

    Any arithmetic operation can then be performed on these date numbers, like taking a mean or median:

    mean(numDates)
    median(numDates)
    

    The only problem here, is that you don’t have your dates in a string type, but as numbers. Luckily datenum also accepts numeric input, but you’ll have to give the day, month and year separated in a vector:

    numDate = datenum([year month day])
    

    or as rows in a matrix if you have multiple timestamps.

    So for your specified example data:

    dates=[32381 41081  40581  32381  32981 41081   40981  40581];
    years  = mod(dates,100);
    dates  = (dates-years)./100;
    days   = mod(dates,100);
    months = (dates-days)./100;
    years = years + 1900; % set the years to the 20th century
    
    numDates = datenum([years(:) months(:) days(:)]);
    fprintf('The mean date is %s\n', datestr(mean(numDates)));
    fprintf('The median date is %s\n', datestr(median(numDates)));
    

    In this example I converted the resulting mean and median back to a readable date format using datestr, which takes the serial date number as input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset, the first column of which is the date in the
I have a dataset which is in the format of frequency, direction, normalised power
I have a moderately sized dataset in excel from which I wish to extract
I have DataSet which has 3 columns. Name - insurance comp. name - treatmentDate
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I have created a dataset in my visual studio project which is connected to
Scenario I have a DevExpress DataGrid which is bound to a DataSet in C#.
I have a (disconnected) typed Dataset in an XML, which I query in LINQ:
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which
I have a UltraWinGrid that is bound to a DataSet, in which a couple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.