필터 지우기
필터 지우기

How to convert 'DDMMYYYYhhmm' into 'DD-MM-YYYY hh:mm'

조회 수: 14 (최근 30일)
Ali Saremi
Ali Saremi 2021년 1월 19일
댓글: Ali Saremi 2021년 1월 21일
Hi there,
I have some data (Please see attached the screenshot) in an Excel sheet. I need to convert it into timeseries with two coloumns. Basically, the first coloumn should the date and the second coloumn should be the values. I was wondering if anyone could help me with this.
The data is formatted in two columns separated by a single space:
The first column is the datetime in the following format: 'DDMMYYYYhhmm'. 'DD' is the day of the month as a two digit integer 'MM' is the month of the year as a two digit integer 'YYYY' is the year as a four digit integer 'hh' is the hour of the day (using 24 hour time) as a two digit integer 'mm' is the minute of the hour as a two digit integer.
The second column is the water level reading in metres in the following format: 'si.fff'. 's' is a prefix indicating if the reading is positive or negative positive readings are denoted by a space ' ' negative readings are denoted by a dash '-'. 'i.fff' is the height of the recording in metres
For example, the line '190120380314 3.142' would refer to a height of 3.142 metres recorded at 03:14am on the 19th of January 2038.
Thank you.
Kind regards,
Ali
  댓글 수: 2
Stephen23
Stephen23 2021년 1월 19일
@Ali Saremi: please upload the original data file (not a screenshot) by clicking the paperclip button.
Ali Saremi
Ali Saremi 2021년 1월 19일
@Stephen Cobeldick: Thank you for your reply. I have already uploaded the orginal data file. Look forward to hearing from you.

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

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 1월 19일
편집: Bjorn Gustavsson 2021년 1월 19일
You can do something like this to convert a date-string to another date-string:
datestr(datenum(char(['190120211029';'140219671940']),'ddmmyyyyHHMM'),'yyyy-mm-dd HH:MM')
You can of course replace '190120211029' with the string/char-array with your time instances.
HTH
  댓글 수: 7
Bjorn Gustavsson
Bjorn Gustavsson 2021년 1월 20일
Reading the help and documentation I learned that you can do something like this:
MeasurementTime = datetime(str2num(C_1(:,5:8)),... % Extract year
str2num(C_1(:,3:4)),... % month
str2num(C_1(:,1:2)),... % etc
str2num(C_1(:,9:10)),...
str2num(C_1(:,11:12)),...
zeros(size(C_1(:,11))));
Ali Saremi
Ali Saremi 2021년 1월 21일
Thank you for your help @Bjorn Gustavsson. Much appreciate it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by