christopherh@1: christopherh@1: %READLIST christopherh@1: % list = readlist(filename) christopherh@1: christopherh@1: % read a list of string values line by line from a text file. christopherh@1: % Ignores any line starting with the '%' character christopherh@1: christopherh@1: function [list, success] = readlist(filename) christopherh@1: christopherh@1: list = {}; %list is a cell array christopherh@1: christopherh@1: success = 1; christopherh@1: % open the text file christopherh@1: fid=fopen(filename); christopherh@1: christopherh@1: % if file opened successfully christopherh@1: if fid ~= -1 christopherh@1: christopherh@1: while 1 christopherh@1: line = fgetl(fid); christopherh@1: christopherh@1: %break on end of file christopherh@1: if ~ischar(line), break, end christopherh@1: christopherh@1: %if the line starts with a % then ignore it christopherh@1: if length(line) && line(1) ~= '%' christopherh@1: % otherwise put current line into output list christopherh@1: list = [list line]; christopherh@1: end christopherh@1: christopherh@1: end christopherh@1: christopherh@1: % close the file christopherh@1: fclose(fid); christopherh@1: else christopherh@1: success = 0; christopherh@1: end christopherh@1: