Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我正在使用以下函数在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 更多&回答... |
![]() |
![]() |