![](https://csdnimg.cn/release/download_crawler_static/87859012/bg5.jpg)
1.1.2 记事本与MATLAB的数据交互
%从记事本t.txt中读取数据
load(‘filename.***’) %记事本中记录的全是数据
[name,type, x,y,answer]=textread(‘t.txt’,‘%s Type %n %f %n
%s’,2)
%将Matlab数据写入记事本
fid= fopen('tp.txt','wt'); %文件扩展名可以为:*.dat或*.xls
fprintf(fid,'This is the database of class 1.\n');
name='Sally';types=1;x=3.1;y=45;answer='Yes';
fprintf(fid,'% s Type %u %f %u %s \n',name,types,x,y,answer);
name='Tom';types=2;x=2.5;y=20;answer='No';
fprintf(fid,'% s Type %u %f %u %s \n',name,types,x,y,answer);
fclose(fid);
每一列要保存的变量名 保存的文件名 读取的格式
读取2行数据
%从记事本t.txt中读取数据
load(‘filename.***’) %记事本中记录的全是数据
[name,type, x,y,answer]=textread(‘t.txt’,‘%s Type %n %f %n
%s’,2)
%从记事本t.txt中读取数据
load(‘filename.***’) %记事本中记录的全是数据
[name,type, x,y,answer]=textread(‘t.txt’,‘%s Type %n %f %n
%s’,2)
%从记事本t.txt中读取数据
load(‘filename.***’) %记事本中记录的全是数据
[name,type, x,y,answer]=textread(‘t.txt’,‘%s Type %n %f %n
%s’,2)
%从记事本t.txt中读取数据
load(‘filename.***’) %记事本中记录的全是数据
[name,type, x,y,answer]=textread(‘t.txt’,‘%s Type %n %f %n
%s’,2)