Export data cell array to several csv files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the following script to export data cell array (read and output netCDF files), to excel format. It works great, but I want to export the data for separated csv files instead export them to several excel sheet, the script is:
files = dir('*.nc4') ;
nfiles = length(files) ;
P = cell(nfiles,1) ; % precipitation of all files
date = cell(nfiles,2) ;
time = cell(nfiles,2) ;
for i = 1:nfiles
%%Read dat
date{i,1} = ncreadatt(files(i).name,'/','HDF5_GLOBAL.BeginDate') ;
date{i,2} = ncreadatt(files(i).name,'/','HDF5_GLOBAL.EndDate') ;
%%Read time
time{i,1} = ncreadatt(files(i).name,'/','HDF5_GLOBAL.BeginTime') ;
time{i,2} = ncreadatt(files(i).name,'/','HDF5_GLOBAL.EndTime') ;
%%REad precipitation
P{i} = ncread(files(i).name,'precipitation') ;
end
myfile = 'myfile.xlsx' ;
for i = 1:nfiles
xlswrite(myfile,P{i},i)
end
it's coded by KSSV.
I changed the last part:
myfile = 'myfile.xlsx' ;
for i = 1:nfiles
xlswrite(myfile,P{i},i)
end
to the following:
fid = fopen('test.csv', 'w') ;
fprintf(fid, '%s,', P{i}) ;
fprintf(fid, '%s\n', P{i}) ;
fclose(fid) ;
dlmwrite('test.csv', P{i}, '-append') ;
%and
% myfile = '1.xlsx' ;
for i = 1:nfiles
% csvwrite (myfile,P{i},i)
csvwrite('csvlist.dat',P{i})
type csvlist.dat
end
The result, didn't work out!
I appreciate your help and time!
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur NetCDF dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!