Home > utility > asciiRead.m

asciiRead

PURPOSE ^

asciiRead: Read an ascii file into a matrix

SYNOPSIS ^

function matrix=asciiRead(fileName)

DESCRIPTION ^

 asciiRead: Read an ascii file into a matrix
    Usage: matrix=asciiRead(fileName)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function matrix=asciiRead(fileName)
0002 % asciiRead: Read an ascii file into a matrix
0003 %    Usage: matrix=asciiRead(fileName)
0004 
0005 %    Roger Jang, 20041021
0006 
0007 if nargin<1, selfdemo; return; end
0008 
0009 fid=fopen(fileName, 'rb');
0010 content=fread(fid, inf, 'char');
0011 fclose(fid);
0012 
0013 file=tempname;
0014 %copyfile(fileName, file);    % problematic in version 6.5!
0015 fid=fopen(file, 'wb');
0016 fwrite(fid, content, 'char');
0017 fclose(fid);
0018 load(file);
0019 [junk, b, junk, junk]=fileparts(file);
0020 eval(['matrix=', b, ';']);
0021 delete(file);
0022 
0023 % ====== Self demo
0024 function selfdemo
0025 x=magic(5);
0026 fileName='我的檔案.txt';
0027 asciiWrite(x, fileName);
0028 matrix=asciiRead(fileName);
0029 fprintf('從 "%s" 讀出的內容:\n', fileName);
0030 disp(matrix);

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003