-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaptReadCSVHeaderFile.m
More file actions
37 lines (31 loc) · 915 Bytes
/
aptReadCSVHeaderFile.m
File metadata and controls
37 lines (31 loc) · 915 Bytes
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
function [header, data, dataCell] = aptReadCSVHeaderFile(filename, delimiter, quoted)
fid = fopen(filename, 'r');
if(quoted)
strquoted = '%q';
else
strquoted = '%s';
end
C = textscan(fid,'%s\n',1,'Delimiter','');
C = textscan(C{1}{1},strquoted,'Delimiter',delimiter);
C = C{1};
header = C';
data = nan(0, length(header));
dataCell = cell(0, length(header));
rcount = 1;
C = textscan(fid,'%s\n',1,'Delimiter','');
while(~isempty(C{1}))
C = textscan(C{1}{1},strquoted,'Delimiter',delimiter);
C = strrep(C{1}',',','.');
for j=1:length(header)
if(j>length(C))
data(rcount,j) = str2double('');
dataCell{rcount,j} = '';
else
data(rcount,j) = str2double(C{j});
dataCell{rcount,j} = C{j};
end
end
C = textscan(fid,'%s\n',1,'Delimiter','');
rcount = rcount + 1;
end
fclose(fid);