Why you are opening a file inside the loop? It should be outside the loop. Try this:
%Creating the datafile
% Datafile Operations
fileID = fopen('DSP_HW4.txt', 'wt');
for i = 1:16
Q = [(i);t(i);g(i)];
fprintf(fileID, '%2s', 'n');
fprintf(fileID, '%6s', 'Time');
fprintf(fileID, '%6s', 'g(n)');
fprintf(fileID, '\n');
fprintf(fileID,'%2.0f %+8.3f %+8.3\n', Q);
end
type('DSP_HW4.txt');
fclose(fileID);
