append data to the end of a txt file...works for 1 line...it doesnt work for two lines
조회 수: 9 (최근 30일)
이전 댓글 표시
the above append alength to the end of 111.txt
clc
fid = fopen('C:\Users\Mr Andrew\Desktop\111.txt', 'a');
for k = 1:5
fprintf(fid,'alength \r\n')
end
fclose(fid);
but if i try this
clc
fid = fopen('C:\Users\Mr Andrew\Desktop\111.vbs', 'a');
for k = 1:5
fprintf(fid,'alength
blength \r\n')
end
fclose(fid);
it doesnt work...what i am doing wrong? thank you...
댓글 수: 0
채택된 답변
추가 답변 (1개)
Madhura Suresh
2013년 8월 26일
Use '\n' to add a new line before writing 'blength'
clc
fid = fopen('C:\Users\Mr Andrew\Desktop\111.txt', 'a');
for k = 1:5
fprintf(fid,'alength\n blength \r\n')
end
fclose(fid);
댓글 수: 2
Madhura Suresh
2013년 8월 26일
편집: Madhura Suresh
2013년 8월 26일
No, the '\n' between 'alength' and 'blength' will move the pointer to the next line. My output was:
alength
blength
alength
blength
alength
blength
alength
blength
alength
blength
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!