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

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

 Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 26 de Sept. de 2014
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 comentarios

Luke
Luke el 26 de Sept. de 2014
Thank you so much. However, how can I then open the created .txt file in Notepad?
Luke
Luke el 26 de Sept. de 2014
Actually, I don't need to open in in Notepad, just have it load the .txt file onto my desktop
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.
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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Sept. de 2014

Comentada:

el 26 de Sept. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by