Export data cell array to several csv files
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!