필터 지우기
필터 지우기

how to add to txt file from certain point

조회 수: 1 (최근 30일)
Ilana
Ilana 2013년 8월 5일
Hi, I have a txt file which is a matrix [col1 col2 col3] (n rows) , i want to input a loop i=1:1:7 that will be added as a 4th col. [col1 col2 col3 1] [col1 col2 col3 2] [col1 col2 col3 3] so on until [col1 col2 col3 7] and then repeat itself until the n row, how can i do that?

채택된 답변

Cedric
Cedric 2013년 8월 5일
편집: Cedric 2013년 8월 5일
One way would be the following:
fid_in = fopen('inFile.txt', 'r') ;
fid_out = fopen('outFile.txt', 'w') ;
cnt = 0 ;
while ~feof(fid_in)
if cnt == 7, cnt = 1 ; else cnt = cnt + 1 ; end
fprintf(fid_out, '%s %d\r\n', fgetl(fid_in), cnt) ;
end
fclose(fid_in) ;
fclose(fid_out) ;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by