Mercurial > hg > dcase2013_ed_vuegenetal
comparison functions/funcsMobilab/readCSV.m @ 0:2fadb31a9d55 tip
Import code by Vuegen et al
author | Dan Stowell <dan.stowell@elec.qmul.ac.uk> |
---|---|
date | Fri, 11 Oct 2013 12:02:43 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2fadb31a9d55 |
---|---|
1 function [txt_struct] = readCSV(file) | |
2 | |
3 % text openen om volledig in te lezen | |
4 fid = fopen(file); | |
5 txt = ''; | |
6 if fid ~= -1 | |
7 while 1 | |
8 line = fgetl(fid); | |
9 if ~ischar(line), break, end | |
10 txt = [txt line ' \n ']; | |
11 end | |
12 end | |
13 fclose(fid); | |
14 | |
15 % text aanpassen | |
16 txt_struct = {}; | |
17 l = 1; | |
18 k = 1; | |
19 voorlopigVak = ''; | |
20 volgendeOverslaan = false; | |
21 for i = 1:length(txt) | |
22 switch txt(i) | |
23 case ';' | |
24 txt_struct{l,k} = voorlopigVak; | |
25 voorlopigVak = ''; | |
26 k = k+1; | |
27 case '\' | |
28 if txt(i+1) == 'n' | |
29 txt_struct{l,k} = voorlopigVak; | |
30 voorlopigVak = ''; | |
31 l = l+1; | |
32 k = 1; | |
33 volgendeOverslaan = true; | |
34 else | |
35 if volgendeOverslaan == false | |
36 voorlopigVak = [voorlopigVak txt(i)]; | |
37 else | |
38 volgendeOverslaan = false; | |
39 end | |
40 end | |
41 otherwise | |
42 if volgendeOverslaan == false | |
43 voorlopigVak = [voorlopigVak txt(i)]; | |
44 else | |
45 volgendeOverslaan = false; | |
46 end | |
47 end | |
48 end | |
49 | |
50 % lege lijnen (of met spaties) onderaan wissen | |
51 ok = false; | |
52 while ok == false | |
53 for i = 1:size(txt_struct,2); | |
54 for j = 1:length(txt_struct{end,i}) | |
55 if not(strcmp(txt_struct{end,i}(j), ' ')) | |
56 ok = true; | |
57 end | |
58 end | |
59 end | |
60 if ok == false | |
61 txt_struct = txt_struct(1:end-1,:); | |
62 end | |
63 end | |
64 end |