0001 function matrix=asciiRead(fileName)
0002
0003
0004
0005
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
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
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);