Hello folks,
in my Simulink model I want to create a block which will read from a file from time to time. The file will not be updated every time the block runs, so in order to save the performance for fopen'ing the file I would just like to check on the file date and time.
Is there any handy Matlab function which will return the file's date and time as a number (e.g. double, 32 bit int etc.)
This is for Matlab / Simulink R2012a, running on WinXP.
Thanks for any hints
Norbert

 채택된 답변

TAB
TAB 2012년 3월 23일

1 개 추천

FileInfo = dir('YourFileWithExtention');
TimeStamp = FileInfo.date;
By the way, in which block of simulink you are using fopen.
[Edited 26 Mar, 2012]
% Get individual components of date & time in 1 Sec resolution
FileInfo = dir('YourFileWithExtention');
[Y, M, D, H, MN, S] = datevec(FileInfo.datenum);
Declare datevec as extrinsic before using.

댓글 수: 4

Jan
Jan 2012년 3월 23일
Or: FileInfo.datenum
Norbert
Norbert 2012년 3월 26일
Thanks for your answer TAB, it is surely helpful. As I see it this method will give me the file date and time with one minute resolution.
Do you know of a way to also get the seconds of the file date and time?
TAB
TAB 2012년 3월 26일
Above functions always returns time with 1 sec resolution.
FileInfo.date will resurn the whole value as string.
If you are using embedded matlab function block, you can also evaluate the invidual values of Year, date, month.....etc.
Please see my edited answer.
Jan
Jan 2012년 3월 26일
The datenum field contains even fractional seconds.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Norbert
Norbert 2012년 3월 26일

0 개 추천

Since I only need to detect a change of the file I will now use the Bytes field of the structure and check for a change of size, this will also work for me.
Btw. I am not sure I understand your question. I use a "Matlab Function" block. I have to declare the fopen as "extrinsic" though.
Tony Jiang
Tony Jiang 2016년 6월 2일
편집: Tony Jiang 2016년 6월 2일

0 개 추천

datestr(FileInfo.date,29) will report the date only without the time info. you can play with the different formatting in datestr though..

카테고리

도움말 센터File Exchange에서 Search Path에 대해 자세히 알아보기

질문:

2012년 3월 23일

편집:

2016년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by