2012-08-31 6 views
0

도움 주셔서 감사합니다! 먼저 matlab 폴더에 텍스트 파일 text.txt가 저장되어 있습니다. 이 파일을 읽고 프로그램을 실행할 때 텍스트를 표시하고 싶습니다. 나는 또한 Goal이라는 단어로 텍스트의 특정 지점까지만 표시하고자합니다.Matlab 도움말, 텍스트 파일 읽기 및 줄 인쇄

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

fprintf(fid, '%s'); 

fclose(fid); 

이것은 특정 텍스트 지점까지 표시하지 않고 나의 첫 번째 부분입니다. 내가 생각한 것은 파일을 열어서 읽은 다음 문서를 인쇄 한 다음 파일을 닫는 것입니다. 나는 어떤 오류나 아무것도 얻지 못했지만, 재 인쇄되는 문서를 보지 못한다. 그것을 인쇄하는 방법에 대한 아이디어는 도움이 될 것입니다!

답변

0

여기 fprintf(fid, '%s')은 그 파일에 내용을 인쇄하는 것을 의미합니다.

사용

fscanf(fid, '%s', s) 
print(s) 

파일에서 읽을 수 있습니다.

사용

s = 'abc' 
fprintf(fid, '%s', s) 

해당 파일을 인쇄합니다. 해당 파일로 인쇄 할 경우, 당신은

을하는 데 도움이
0
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 

fid = fopen('text.txt', 'rw+') 
희망을 사용해야합니다