Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:30   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 从文件中读取浮点数和字符串

我正在使用以下函数在MATLAB中写入和读取4098浮点数:

写作:

fid = fopen(completepath, 'w'); fprintf(fid, '%1.30f\r\n', y) 阅读:

data = textread(completepath, '%f', 4098); 其中y包含4098个数字。我现在想在此数据的末尾写入和读取3个字符串。如何读取两种不同的数据类型?请帮我。提前致谢。



回答:

这里是什么,我觉得你想要做的,用一个例子TEXTSCAN用于读取文件,而不是TEXTREAD (将在MATLAB的未来版本中删除):

%# Writing to the file: fid = fopen(completepath,'w'); %# Open the file fprintf(fid,'%1.30f\r\n',y); %# Write the data fprintf(fid,'Hello\r\n'); %# Write string 1 fprintf(fid,'there\r\n'); %# Write string 2 fprintf(fid,'world!\r\n'); %# Write string 3 fclose(fid); %# Close the file %# Reading from the file: fid = fopen(completepath,'r'); %# Open the file data = textscan(fid,'%f',4098); %# Read the data stringData = textscan(fid,'%s',3); %# Read the strings fclose(fid); %# Close the file

更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 23:32


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.