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个字符串。如何读取两种不同的数据类型?请帮我。提前致谢。
回答:
这里是什么,我觉得你想要做的,用一个例子TEXTSCAN (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textscan.html)用于读取文件,而不是TEXTREAD (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textread.html) (将在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
更多&回答... (https://stackoverflow.com/questions/2616003)
写作:
fid = fopen(completepath, 'w'); fprintf(fid, '%1.30f\r\n', y) 阅读:
data = textread(completepath, '%f', 4098); 其中y包含4098个数字。我现在想在此数据的末尾写入和读取3个字符串。如何读取两种不同的数据类型?请帮我。提前致谢。
回答:
这里是什么,我觉得你想要做的,用一个例子TEXTSCAN (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textscan.html)用于读取文件,而不是TEXTREAD (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textread.html) (将在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
更多&回答... (https://stackoverflow.com/questions/2616003)