How to load an Excel file that changes with the date?

3 views (last 30 days)
I've created a script that loads and creates a graph from the reliability of the computers within a department. The excel file that contains the data is created new each morning with the date that it is loading for. The date that comes up is in the format such as 30_9_2019, I have requested for it to be changed to a dd_mm_yyyy format, as when trying the
>> date = today('datetime')
date =
datetime
30-Sep-2019
>> formatOut = 'dd_mm_yyyy'
formatOut =
'dd_mm_yyyy'
>> datestr(now,formatOut)
ans =
'30_09_2019'
The whole title for the file is currently d_m_yyyy_04_01_AMReliability.csv with the day and month varying between dd and mm depending on the date, of course.
One issue I find is that when you trt and get Matlab to run from dd_m_yyyy it comes up with a letter for the month.
Is there any way I can get matlab to find the new name automatically as otherwise the date has to be changed and run manually every morning.

Accepted Answer

meghannmarie
meghannmarie on 30 Sep 2019
You could just convert numbers to string and piece it together like this:
date = datetime('now');
[y,m,d] = ymd(date);
filename = [num2str(d) '_' num2str(m) '_' num2str(y) '_04_01_AMReliability.csv ']
  1 Comment
Sophia Collinson
Sophia Collinson on 1 Oct 2019
Thank you so much! That's exactly what I needed, it all works perfectly now!

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!