diff evaluationtools/readlist.m @ 1:8973548174c1 tip

adding tools to repo
author christopherh
date Mon, 06 May 2013 14:43:47 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/evaluationtools/readlist.m	Mon May 06 14:43:47 2013 +0100
@@ -0,0 +1,38 @@
+
+%READLIST
+% list = readlist(filename)
+
+% read a list of string values line by line from a text file. 
+% Ignores any line starting with the '%' character
+
+function [list, success] = readlist(filename)
+
+list = {}; %list is a cell array
+
+success = 1;
+% open the text file
+fid=fopen(filename); 
+
+% if file opened successfully
+if fid ~= -1
+    
+    while 1 
+        line = fgetl(fid);
+        
+        %break on end of file
+        if ~ischar(line), break, end
+
+        %if the line starts with a % then ignore it
+        if length(line) && line(1) ~= '%' 
+            % otherwise put current line into output list
+            list = [list line];
+        end  
+
+    end
+    
+    % close the file
+    fclose(fid);
+else
+    success = 0;
+end
+