フィルターのクリア

Export data cell array to several csv files

1 回表示 (過去 30 日間)
Majid Mohamod
Majid Mohamod 2017 年 6 月 6 日
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 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by