MATLAB: How to open new text file and how to write on the text file using matlab code

fileMATLABtext filetext;

How to open new text file and how to write on the text file using matlab code?
PS: How to go to next line(like we use Enter to go to next line) on the text file using code….can anyone help

Best Answer

Try something like this
fid = fopen(filename, 'wt');
if fid ~= -1
fprintf('This is line 1. Backslash n makes a new line.\n');
fprintf('My result is %f\n, result);
fprintf('My string = %s\n', myString);
fclose(fid);
else
warningMessage = sprintf('Cannot open file %s', filename);
uiwait(warndlg(warningMessage));
end