How Can I Load and Format Dates in MATLAB from an Excel or Text File?

  • Context: MATLAB 
  • Thread starter Thread starter carlosvelcab
  • Start date Start date
  • Tags Tags
    Load Matlab
Click For Summary
SUMMARY

This discussion addresses the process of loading and formatting dates in MATLAB from Excel and text files. Users can convert date strings into MATLAB's date-type variables using the datenum function, specifically with the format datenum('2000 03 01', 'yyyy dd mm'). To display these dates in a readable format, the datestr function is utilized, allowing for outputs such as datestr(time, 'mmmm dd, yyyy'). A combined approach is recommended for optimal results: datestr(datenum('2000 03 01', 'yyyy dd mm'), 'mmmm dd, yyyy').

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of date formatting in MATLAB
  • Basic knowledge of Excel file handling in MATLAB
  • Experience with string manipulation in MATLAB
NEXT STEPS
  • Research the datenum function in MATLAB for date conversion
  • Explore the datestr function for formatting dates
  • Learn about importing data from Excel files using readtable or xlsread
  • Investigate MATLAB's datetime data type for enhanced date handling
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers who need to manipulate and format date data from external files, particularly those transitioning from Excel or text formats.

carlosvelcab
Messages
4
Reaction score
0
hi every one, I have a problem for load dates in matlab, I have 2488 dates
in xls file and txt file but I can't make that MATLAB read the number as a dates? Does anybody know how to do it?
for example I have this:
2000 03 01
2000 04 01
2000 05 01
2000 06 01
.
.
.

And I want that MATLAB shows me

03-Jan-2000
04-Jan-2000
05-Jan-2000

please help me
 
Physics news on Phys.org
++ Firstly, you need to convert string to date-type variable by using datenum.
Ex: datenum('2000 03 01', 'yyyy dd mm')

++ Secondly, using datestr:
Ex: datestr(time, 'mmmm dd, yyyy')

Combining: datestr(datenum('2000 03 01', 'yyyy dd mm'), 'mmmm dd, yyyy')

Hope this helps
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 7 ·
Replies
7
Views
8K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K