フィルターのクリア

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) ;
  1 件のコメント
Ilana
Ilana 2013 年 8 月 6 日
Works! thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by