fprintf of cell array
Afficher commentaires plus anciens
I am trying to generate text files from the following example:
clear all
Year = {'2007','2008','2009'};
for i = 1:length(Year)
StartDate{i} = [Year{i} '-01-01 00:00'];
EndDate{i} = [Year{i} '-12-31 23:57'];
Resolution = 60;
DateT{i} = datestr(datenum(StartDate{i},'yyyy-mm-dd HH:MM'):Resolution/(60*24):...
datenum(EndDate{i},'yyyy-mm-dd HH:MM'),'yyyy-mm-dd HH:MM');
DateTime{i} = cellstr(DateT{i});
end
%save as text file
for i = 1:length(Year);
mkdir(fullfile('C:',Year{i}));
filename{i} = fullfile('C:',Year{i},'DateTime.txt');
fid{i} = fopen(filename{i},'w+');
for ii = 1:length(DateTime);
a{i} = 1:length(DateTime{i});
for k = 1:a{i};
fprintf(fid{i},'%s',DateTime{i}{k});
end
end
end
fclose 'all';
I know that the error must be in the line containing fprintf but I dont know how to fix it. How is it possible to write the each cell of DateTime into separate text files as indicated in the script?
1 commentaire
Mohammed Ibrahim
le 10 Nov 2016
I had similar problem, I used strcat after cellstr. so in this question this may work: DateTime{i} = strcat(cellstr(DateT{i}));
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings 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!