Convert dates in MATLAB that show up with the opposite year

조회 수: 1 (최근 30일)
BA
BA 2022년 7월 21일
댓글: Walter Roberson 2022년 7월 22일
Having some trouble w/ my data.
The dates are showing up wrong. For example:
3/9/9102
3/10/9102
Obviously, i didn't collect data in 9102 and if you read it backwards, its 2019 which would be the correct date.
Does anyone know how to correct for this?
For example, how would you convert
3/9/9102 --> 3/9/2019
If someone knows, let me know. Thanks
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 7월 22일
Duplicated by later https://www.mathworks.com/matlabcentral/answers/1765405-trouble-using-split-function-in-matlab?s_tid=srchtitle which has solutions

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

채택된 답변

SAI SRUJAN
SAI SRUJAN 2022년 7월 21일
Hi SS,
From my understanding of your question,you want to reverse the year part of the date.Im assuming that the dates are in the string format.The following code snippet might help,
date='3/9/9102';
arr=split(date,'/');
arr(3)=reverse(arr(3));
date=char(join(arr,'/'));
  댓글 수: 2
BA
BA 2022년 7월 22일
Thanks a lot for responding!
The code does work for one variable, but unfortunately, when its in a column, I keep getting this error message:
"Error using split
First argument must be text."
For example,
%Generate data
dates = ['3/11/9102'; '3/12/9102'; '3/13/9201'; '3/14/9102'];
%Fix backwards year
splitter = split(dates,'/');
Error using split
First argument must be text.
splitter(3) = reverse(splitter(3));
dates_new = char(join(splitter,'/'));
BA
BA 2022년 7월 22일
Nvm, thank you!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by