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