필터 지우기
필터 지우기

Using fprintf to open a .txt file of text (NOT data)

조회 수: 2 (최근 30일)
Luke
Luke 2014년 9월 26일
댓글: Mohammad Abouali 2014년 9월 26일
Hey guys, I'm new here. I'm having some issues with using the fprintf command. I want to use it to print actual words (NOT data, like a matrix) to a .txt file on my desktop. I've been all over the internet trying to figure out how to do this, but I can't seem to find anything regarding the fprintf command and opening things that aren't data sets.
Thanks in advance, Luke

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 9월 26일
fid=fopen('test.txt','w');
str='Actual textual thing, Once upon a time there was a princess trapped in the tower.';
fprintf(fid,'%s\n',str);
str='Same old story, at the end some guy freed the princes.';
fprintf(fid,'%s\n',str);
fclose(fid);
  댓글 수: 4
Image Analyst
Image Analyst 2014년 9월 26일
Specify the folder
folder = 'c:\users\Luke\Desktop'; % Wherever you want
fullFileName = fullfile(folder, 'test.txt');
fid = fopen(fullFileName, 'wt');
To pen in Notepad, use the system() function or winopen() function.
Mohammad Abouali
Mohammad Abouali 2014년 9월 26일
As image analyst said, either use:
winopen(fullPath_filename);
or use
system(['notepad ' fullPath_filename]);
and fullPath_filename is pretty much what you used in fopen function.
But What is it that you want to do? Do you want to convey a message to the user or something? May be there is another approach that could be more beneficial!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by