Creating ASCII file with 2 columns
Afficher commentaires plus anciens
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);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!