Hey I have a textfile: The first coloumn represents year/month and rest of the coloumns are deviations.
txt.PNG
I want to convert the first coloumn to a serial date num. Meaning total days from 0.january, 0000. With the function datenum.
What I have tried is to first import the txt file, lets call it get.txt
f = importdata("get.txt");
Then assign the first coloumn to variable fdate.
fdate = f.textdata;
Then Ive tried to use the datenum function
x = datenum(fdate, "yyyy-mm")
The error I get is:
Error using dtstr2dtnummx
Failed to convert from text to date number.

댓글 수: 1

Guillaume
Guillaume 2019년 9월 23일
I want to convert the first coloumn to a serial date num
Why? Unless you're using a very old version of matlab, using datetime would make a lot more sense.
Attaching an example text file instead of a screenshot (which we can't use for testing) is a lot more useful.
Indicating which version of matlab you use would be useful as well. There's a field to the right of question where you can enter the product (matlab) and the version.

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

 채택된 답변

Stephen23
Stephen23 2019년 9월 23일

0 개 추천

datenum(fdate, "yyyy-mm")
% ^ this character does not match your date data!

댓글 수: 2

Olaf
Olaf 2019년 9월 23일
Oh thanks so much. How can I then show total days from 0 january, 0000 for each row?
If you use datetime as I commented, dead easy:
days(yourdatetimearray - datetime(0, 0, 0))

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2019년 9월 23일

댓글:

2019년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by