diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/functions/funcsMobilab/readCSV.m	Fri Oct 11 12:02:43 2013 +0100
@@ -0,0 +1,64 @@
+function [txt_struct] = readCSV(file)
+
+    % text openen om volledig in te lezen
+    fid = fopen(file);
+    txt = '';
+    if fid ~= -1
+        while 1
+            line = fgetl(fid);
+            if ~ischar(line), break, end
+            txt = [txt line ' \n '];
+        end
+    end
+    fclose(fid);
+    
+    % text aanpassen
+    txt_struct = {};
+    l = 1;
+    k = 1;
+    voorlopigVak = '';
+    volgendeOverslaan = false;
+    for i = 1:length(txt)
+        switch txt(i)
+            case ';'
+                txt_struct{l,k} = voorlopigVak;
+                voorlopigVak = '';
+                k = k+1;
+            case '\'
+                if txt(i+1) == 'n'
+                    txt_struct{l,k} = voorlopigVak;
+                    voorlopigVak = '';
+                    l = l+1;
+                    k = 1;
+                    volgendeOverslaan = true;
+                else
+                    if volgendeOverslaan == false
+                        voorlopigVak = [voorlopigVak txt(i)];
+                    else
+                        volgendeOverslaan = false;
+                    end
+                end
+            otherwise
+                if volgendeOverslaan == false
+                    voorlopigVak = [voorlopigVak txt(i)];
+                else
+                    volgendeOverslaan = false;
+                end
+        end
+    end
+    
+    % lege lijnen (of met spaties) onderaan wissen
+    ok = false;
+    while ok == false
+        for i = 1:size(txt_struct,2);
+            for j = 1:length(txt_struct{end,i})
+                if not(strcmp(txt_struct{end,i}(j), ' '))
+                    ok = true;
+                end
+            end
+        end
+        if ok == false
+            txt_struct = txt_struct(1:end-1,:);
+        end
+    end
+end