필터 지우기
필터 지우기

Creating an ASCII file - blank txt file

조회 수: 13 (최근 30일)
D.J
D.J 2018년 9월 2일
댓글: D.J 2018년 9월 2일
Hello, I am trying to create an ASCII file containing a DATE column. I managed to get the code, but the txt file I am getting is not showing the dates. I can't figure out what am I doing wrong ! any help would be highly appreciated ! I have attached the data file and the txt file I am getting, and following is my code:
[DATE]=importfile('Air_Density.csv');
DateStrings = {'01-07';'02-07';'03-07';'04-07';'05-07';'06-07';'07-07';'08-07';'09-07';'10-07';'11-07';'12-07';'13-07';'14-07';'15-07';'16-07';'17-07';'18-07';'19-07';'20-07';'21-07';'22-07';'23-07';'24-07';'25-07';'26-07';'27-07';'28-07';'29-07';'30-07';'31-07'};
%t = datetime(DateStrings,'InputFormat',infmt)
d=datetime(DateStrings,'InputFormat','dd-MM');
FID=fopen('filename.txt','w');
fprintf(FID,'%6s \n','DATE');
fprintf(FID,'%6s \n',d);
fclose(FID);
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 9월 2일
fprintf(FID,'%6s \n','DATE'); requests to print the literal string 'DATE'.
fprintf(FID,'%6s \n',DATE); would request to output the content of the variable DATE
D.J
D.J 2018년 9월 2일
I have just realised that I have done something wrong in my question here. I updated the data file and my code. I have edited the 2nd fprintf as you suggested, but now I am getting the error:
Error using fprintf
Function is not defined for 'datetime' inputs.
Error in Q14_1 (line 10)
fprintf(FID,'%6s \n',d);

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 2일
dc = cellstr(d);
fprintf(FID,'%6s \n', dc{:});
  댓글 수: 1
D.J
D.J 2018년 9월 2일
Perfect ! Thanks a lot Walter !!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by