MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   从文件中读取浮点数和字符串 (https://www.labfans.com/bbs/showthread.php?t=23298)

poster 2019-12-10 20:30

从文件中读取浮点数和字符串
 
我正在使用以下函数在MATLAB中写入和读取4098浮点数:

写作:

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

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



[B]回答:[/B]

这里是什么,我觉得你想要做的,用一个例子[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textscan.html"]TEXTSCAN[/URL]用于读取文件,而不是[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textread.html"]TEXTREAD[/URL] (将在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

[url=https://stackoverflow.com/questions/2616003]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 05:09

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