Filter löschen
Filter löschen

Function Writing to a text file

2 Ansichten (letzte 30 Tage)
Caroline am 12 Okt. 2014
Beantwortet: Image Analyst am 12 Okt. 2014
I am using a function to produce a madlib in a sense and it has to print to the command window and save to a text file. It prints fine to the command window but isn't saving to the text file and no error is showing up. This is what I have so far.
%open file to save to
%print to file and command window
%close file
mad lib:this is actually a whole story but its very long

Akzeptierte Antwort

Image Analyst
Image Analyst am 12 Okt. 2014
Try it this way instead, with '%s'
% Open a text file to save the string to.
fid = fopen('story1.txt', 'wt'); % Use wt instead of w
% Print string to the file and command window.
fprintf(fid, '%s\n', y) % y is a string. Prints to a file.
fprintf('%s\n', y) % Print to command window instead of a file.
% Close the file;

Weitere Antworten (0)


Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by