필터 지우기
필터 지우기

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 CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by