方法一
http://www.youtube.com/watch?v=9Fuc6T4_74M
fid = fopen('input.txt', 'r');
data = fread(fid);
CharData = char(data);
fclose(fid);
input = CharData;
e.g
input =
b
a
t
!
!
c
a
t
c
a
t
方法二
fidin = fopen('input.txt'); % open input.txt
fidout = fopen('data.txt','w'); % create data.txt
while ~feof(fidin) % end of file?
tline = fgetl(fidin); % read lines
fprintf(fidout,'%s\n\n',tline); % wirte to file.txt
end
fclose(fidout);
input = importdata('data.txt'); % import data.txt into workspace: variable = input
input = cell2mat(input);
本文详细介绍了如何使用MATLAB从文本文件中读取数据并进行导入的两种方法,包括直接读取和通过中间文件操作。适用于需要从外部文本文件获取数据进行进一步处理的场景。
6311

被折叠的 条评论
为什么被折叠?



