datenum question - combination of date and time

조회 수: 9 (최근 30일)
Bearli Ubuku
Bearli Ubuku 2011년 8월 4일
Hi,
I just started using Matlab to process some experimental data. Certain concentration data and the according time (HH:MM:SS) are logged in a txt file. I am able to extract a single cell (1500x1) containing all times (as said in the format HH:MM:SS). I also have a single cell containig the date (e.g. 04.04.2004). For later purposes I would like to have a vector containing serial date numbers implicitly describing time and date.
I already had some tries where I first converted the points in time to serial date numbers and later on added the converted date to the aforementioned values: Wizhout success.
What I actually especially wonder about is the following code:
test=datenum('00:05:00','HH:MM:SS')
test =
7.3450e+005
>> datestr(test,'dd.mm.yyyy HH:MM:SS')
ans =
01.01.2011 00:05:00
Shouldn't the answer be "01.01.0000 00:05:00" instead?
Thanks in advance,
bearli

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 4일
From the documentation of datestr(). "For date formats that specify only a time (i.e., dateform numbers 13, 14, 15, and 16), MATLAB sets the date to January 1 of the current year."

추가 답변 (1개)

Bearli Ubuku
Bearli Ubuku 2011년 8월 4일
Thanks for the quick reply!
How would I actually put this into practice in a way that my code will work next year with this years data as well? A simplification of my problem would be a DateStringArray which is
cTimeOnly={'18:05:41'; '18:06:11'}
and the date:
cSingleDate={'21.01.2011'}
Thanks in advance again,
bearli
  댓글 수: 4
Walter Roberson
Walter Roberson 2011년 8월 4일
If you have that information, why not just concatenate the parts together and skip converting to date numbers? That is, the original question implies that the desired output is the date string anyhow.
Bearli Ubuku
Bearli Ubuku 2011년 8월 4일
Well the code I wrote in the first part was just something I tripped over when I played around with the datenum command. And about Fangjuns answer:
I already tried something in that direction. But the problem actually was the concatenating. I just used {} instead of strcat. -> dimensions
The final output might be the date string, but certainly in various modifications. And in principle isn't it better to have a serial date number to start with (and store)?

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

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by