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 file
    end
    fclose(fid);