Mercurial > hg > c4dm-chord-transcriptions
annotate evaluationtools/readlist.m @ 1:8973548174c1 tip
adding tools to repo
author | christopherh |
---|---|
date | Mon, 06 May 2013 14:43:47 +0100 |
parents | |
children |
rev | line source |
---|---|
christopherh@1 | 1 |
christopherh@1 | 2 %READLIST |
christopherh@1 | 3 % list = readlist(filename) |
christopherh@1 | 4 |
christopherh@1 | 5 % read a list of string values line by line from a text file. |
christopherh@1 | 6 % Ignores any line starting with the '%' character |
christopherh@1 | 7 |
christopherh@1 | 8 function [list, success] = readlist(filename) |
christopherh@1 | 9 |
christopherh@1 | 10 list = {}; %list is a cell array |
christopherh@1 | 11 |
christopherh@1 | 12 success = 1; |
christopherh@1 | 13 % open the text file |
christopherh@1 | 14 fid=fopen(filename); |
christopherh@1 | 15 |
christopherh@1 | 16 % if file opened successfully |
christopherh@1 | 17 if fid ~= -1 |
christopherh@1 | 18 |
christopherh@1 | 19 while 1 |
christopherh@1 | 20 line = fgetl(fid); |
christopherh@1 | 21 |
christopherh@1 | 22 %break on end of file |
christopherh@1 | 23 if ~ischar(line), break, end |
christopherh@1 | 24 |
christopherh@1 | 25 %if the line starts with a % then ignore it |
christopherh@1 | 26 if length(line) && line(1) ~= '%' |
christopherh@1 | 27 % otherwise put current line into output list |
christopherh@1 | 28 list = [list line]; |
christopherh@1 | 29 end |
christopherh@1 | 30 |
christopherh@1 | 31 end |
christopherh@1 | 32 |
christopherh@1 | 33 % close the file |
christopherh@1 | 34 fclose(fid); |
christopherh@1 | 35 else |
christopherh@1 | 36 success = 0; |
christopherh@1 | 37 end |
christopherh@1 | 38 |