-
Notifications
You must be signed in to change notification settings - Fork 1
/
cell2csv.m
48 lines (40 loc) · 1.2 KB
/
cell2csv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function cell2csv(datName,cellArray,trennZeichen,quoteChar)
%CELL2CSV (ps-utils) Writes Cell-Array content into csv.
%
% CELL2CSV(DATNAME,CELLARRAY,TRENNZEICHEN,QUOTECHAR)
%
% DATNAME = Name of the file to save. [ i.e. 'text.csv' ]
% CELLARRAY = Name of the Cell Array where the data is in
% TRENNZEICHEN = seperating sign, normally:',' it's default
% QUOTECHAR default '"', character to use to quote strings
%
% MH - http://github.com/histed/tools-mh
% based on code by Sylvain Fiedler, KA, 2004
if nargin < 3 || isempty(trennZeichen)
trennZeichen = ',';
end
if nargin < 4 || isempty(quoteChar)
quoteChar = '"';
end
datei = fopen(datName,'w');
for z=1:size(cellArray,1)
for s=1:size(cellArray,2)
var = eval(['cellArray{z,s}']);
var = var(:);
if length(var) == 0
% empty
var = '';
elseif isnumeric(var)
var = num2str(var);
else
% character, surround with quotes
var = [quoteChar; var; quoteChar];
end
fprintf(datei,var);
if s ~= size(cellArray,2)
fprintf(datei,trennZeichen);
end
end
fprintf(datei,'\n');
end
fclose(datei);