I have the hardest time formatting my data files!
Every time I try running this the code goes into an infinite loop.
Also, I'd like to start the top n value at 0 if possible
%Creating the datafile
% Datafile Operations
for i = 1:16
Q = [(i);t(i);g(i)];
fileID = fopen('DSP_HW4.txt', 'wt');
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);

 채택된 답변

KSSV
KSSV 2018년 2월 27일

1 개 추천

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);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

질문:

2018년 2월 27일

답변:

2018년 2월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by