MATLAB: I’d like to create a loop that each time adds a new line to a .txt file. etcmatrixtext filevector I have a loop that generates a vector each time it loops through . my_vector = [ 4, 5, 6,7]; I'd like to create a loop that each time adds the new vector to a .txt file. Best Answer fid = fopen('Output.txt', 'wt');for K = 1 : 10000 my_vector = randi(10,1,4); %generate vector fprintf(fid, '%d %d %d %d\n', my_vector); adds new vector to text fileendfclose(fid); Related SolutionsMATLAB: Issue with data format when using textscan() The format should be all lower case for duration.%{hh:mm:ss}THowever, the data appears to be delimited as semicolon. You'd have more luck with readtable:opts = detectImportOptions('D:\SI010118.txt')opts = setvartype(opts,1,'datetime')opts = setvaropts(opts,1,'InputFormat','dd.MM.uuuu HH:mm:ss')readtable('D:\SI010118.txt',opts) MATLAB: Writing text file fid = fopen('exp.txt', 'w');fprintf(fid, '%g\n', time);fclose(fid); Related QuestionLoading vectors with multiple dimensions from a .txt fileHow to use repmat in the textscan()Creating log of matlab run script with time and dateImport data into a txt file from matlabHi, How to remove white spaces from A=[1 0 0 0 1] binary data & how to copy the binary data in A to a text file?. Thanks in advance.Save as ascii filesSave syms into a file txt
Best Answer