Merge branch 'fixf'
[wrf-fire-matlab.git] / util1_jan / cell2csv.m
blob2eb823209e9f0fb2c61d33600cef4d8f27a033e1
1 function cell2csv(raw,file)
2 % cell2csv(raw,file)
3 % Write cell array raw to csv file
4 % Needed because xlswrite does not work
5 % Usage:
6 %     [num,txt,raw] = xlsread('file.xls')
7 %     cell2csv(raw,'file.csv')
8 % will copy xls file to csv file
9 f=fopen(file,'w');
10 [m,n]=size(raw);
11 for i=1:m
12     for j=1:n
13         a=raw{i,j};
14         if isnan(a),
15         elseif isnumeric(a) & isscalar(a),
16             fprintf(f,'%20.12g',a);
17         elseif ischar(a),
18             fprintf(f,'"%s"',a);
19         else
20             error('entries must be numeric scalars or strings')
21         end
22         if j<n,
23             fprintf(f,',');
24         else
25             fprintf(f,'\n');
26         end
27     end
28 end
29 fclose(f);
30 %t=cell2table(raw);
31 %writetable(t,file,'Delimiter',',','QuoteStrings',true,...
32 %    'WriteVariableNames',false)
33 %end
34