Creating ASCII file with 2 columns
이전 댓글 표시
Hello, I am trying to create an ASCII file containing 2 columns: Date an Density. I managed to get the code to work well if I create 2 separate m files to each of them, but when I merge them, the filename.txt doesn't retrieve the data correctly. It only shows dates and in the wrong displayNot sure 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:
AirDensity = importfile4('Air_Density.csv', 2, 32);
%Date Data
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'};
DATE_Q14=datetime(DateStrings,'InputFormat','dd-MM');
%converting the datestring 'DATE_Q14' to cell array of strings
DATE_Q14c = cellstr(DATE_Q14);
%Air Density Data
Density=AirDensity(1:end,1);
FID=fopen('filename.txt','w');
fprintf(FID,'%6s \n',['DATE','DENSITY']);
fprintf(FID,'%6s \n', [DATE_Q14c{:},Density{:}]);
fclose(FID);
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!