insert date in date .txt

조회 수: 1 (최근 30일)
Tio Phill
Tio Phill 2019년 10월 21일
편집: KALYAN ACHARJYA 2019년 10월 21일
Hi, I have a series of data that is arranged per month for 5 years (01/2001 - 12/2005)
I would like the first column of my data to be the date written as follows:
200101
200102
200103
.
.
.
200512

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 10월 21일
편집: KALYAN ACHARJYA 2019년 10월 21일
One way, save all file as cell array elements as strings
data_file={'01/2001','02/2001','03/2001','12/2005'}; % Just an example
result=zeros(1,length(data_file));
for i=1:length(data_file)
data=sscanf(data_file{i},'%d/%d'); % This trick from @Walter Sir
data=strcat(num2str(data(2)),num2str(data(1)));
result(i)=str2double(data);
end
result'
There may be more easier solution
Result:
ans =
20011
20012
20013
200512

카테고리

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