Home > atmlab > files > file2strs.m

file2strs

PURPOSE ^

FILE2STRS Converts a file to strings

SYNOPSIS ^

function S = file2strs( filename )

DESCRIPTION ^

 FILE2STRS   Converts a file to strings

    The function reads an ASCII file and puts each row of the file into
    a cell array of strings. That is, S{3} is row 3 of the file.

    Newline characters are not included in the strings.

 FORMAT   S = file2strs( filename )
        
 OUT   S          Cell array of strings. Each array element is a row of the
                  file, without newline character.
 IN    filename   Name of file to read.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

file2strs.m

SOURCE CODE ^

0001 % FILE2STRS   Converts a file to strings
0002 %
0003 %    The function reads an ASCII file and puts each row of the file into
0004 %    a cell array of strings. That is, S{3} is row 3 of the file.
0005 %
0006 %    Newline characters are not included in the strings.
0007 %
0008 % FORMAT   S = file2strs( filename )
0009 %
0010 % OUT   S          Cell array of strings. Each array element is a row of the
0011 %                  file, without newline character.
0012 % IN    filename   Name of file to read.
0013 
0014 % 2002-12-20   Created by Patrick Eriksson.
0015 
0016 
0017 function S = file2strs( filename )
0018                                                                            %&%
0019 %= Check input                                                             %&%
0020 %                                                                          %&%
0021 rqre_nargin( 1, nargin );                                                  %&%
0022 
0023 
0024 %= Open file for reading
0025 %
0026 fid = fileopen( filename, 'r' );
0027 
0028 
0029 %= Loop and read one line at the time (not storing newlines)
0030 %
0031 j = 0;
0032 %
0033 while 1    
0034   
0035   s = fgetl( fid );
0036 
0037   if ~ischar(s)
0038     break 
0039   end
0040 
0041   j = j + 1;
0042 
0043   S{j} = s;
0044 
0045 end
0046 
0047 
0048 %= Close file
0049 %
0050 fid = fileclose( fid );

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005