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

3 ビュー (過去 30 日間)
Sophia Collinson
Sophia Collinson 2019 年 9 月 30 日
コメント済み: Sophia Collinson 2019 年 10 月 1 日
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.

採用された回答

meghannmarie
meghannmarie 2019 年 9 月 30 日
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 件のコメント
Sophia Collinson
Sophia Collinson 2019 年 10 月 1 日
Thank you so much! That's exactly what I needed, it all works perfectly now!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by