Matlab帮助,读取文本文件,然后打印行

Matlab帮助,读取文本文件,然后打印行,matlab,Matlab,谢谢你的帮助! 首先,我有一个文本文件text.txt,保存在我的matlab文件夹中。我想读取此文件,并在运行程序时显示文本。我还只想在文本中的某一点显示Goal这个词 fid = fopen('text.txt', 'r+'); fprintf(fid, '%s'); fclose(fid); 这是我的第一部分,没有显示到文本的某一点。我想我做的是打开文件阅读,然后打印文档,然后关闭文件。我没有收到任何错误或任何东西,但也没有看到文档被重印。任何关于如何打印的想法都会有帮助 此处fpr

谢谢你的帮助! 首先,我有一个文本文件text.txt,保存在我的matlab文件夹中。我想读取此文件,并在运行程序时显示文本。我还只想在文本中的某一点显示Goal这个词

fid = fopen('text.txt', 'r+');

fprintf(fid, '%s');

fclose(fid);
这是我的第一部分,没有显示到文本的某一点。我想我做的是打开文件阅读,然后打印文档,然后关闭文件。我没有收到任何错误或任何东西,但也没有看到文档被重印。任何关于如何打印的想法都会有帮助

此处
fprintf(fid,'%s')
表示将内容打印到该文件中

使用

从文件中读取

使用

打印到该文件。如果您需要打印到该文件,您应该使用

fid = fopen('text.txt', 'rw+')
fid=fopen('c:\text.txt','r');
s=textscan(fid、%s、'delimiter'、'\n');%在获取行数组时,删除分隔符部分以获取单词数组
ss=[s{1}];
fclose(fid);
%在屏幕上逐行打印,或使用字符串数组执行任何操作
i=0
j=长度(ss); 而i i=i+1; 高级惩教主任(高级惩教主任(一)); 结束
希望能有帮助

s = 'abc'
fprintf(fid, '%s', s)
fid = fopen('text.txt', 'rw+')
fid=fopen('c:\text.txt','r');
s=textscan(fid,'%s','delimiter','\n');%u get array of lines, drop the delimiter part to get an array of words
ss=[s{1}];
fclose(fid);

%print out line by line on the screen, or do what ever you want with array of strings ss

i=0;<br>
j=length(ss);
while i < j;%or insert string compare to your 'Goal' word here to stop output if u have array of words in ss like while ~strcmp(ss(i+1),'Goal') or use strfind function to find your key word in lines of text<br>
  i=i+1;
  disp(ss(i));
end