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 thisfid = 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 Related SolutionsMATLAB: Read text file and store in .mat file fid = fopen('file1.txt');A= textscan(fid,'%s');fclose(fid);celldisp(A)save file2 A MATLAB: Creating log of matlab run script with time and date FileName = fullfile(tempdir, 'MyLogFile.txt');Message = 'Hello';fid = fopen(FileName, 'a');if fid == -1 error('Cannot open file: %s', FileName);endfprintf(fid, '%s: %s', datestr(now, 0), Message);fclose(fid);See doc datestr for other formats.With a modern Matlab version:fprintf(fid, '%s: %s', datetime, Message); Related QuestionHow to append three text files together in a new text fileSaving file with file name from userHow to append a text file to another text fileConcatenate data using fgetsMaking an Error GUI
Best Answer