Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Insert row in a text file-formating issues

1 回表示 (過去 30 日間)
Ionut  Anghel
Ionut Anghel 2015 年 6 月 17 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
I have follwing question:
I have a "Mytext.txt" file which contains a formated table [20000X30]. It looks like:
1 2 3 4 .... 30/
2 2 3 4 .... 30/
................
20000 2 3 4...30/
I would like to insert a row after each row from the table such Mynewtext.txt" file should look like:
1 2 3 4 .... 30/
120 30/
2 2 3 4 .... 30/
120 30/
................
20000 2 3 4...30/
The row 120 30/ has to be formatted such that I have ten blanks, 120, again ten blanks and 30.
Thank you

回答 (1 件)

Christiaan
Christiaan 2015 年 6 月 17 日
編集済み: Christiaan 2015 年 6 月 17 日
Dear Ionut,
What you could do is use the import gui tool in MATLAB for importing text files. With this tool, you can determine how you want to import your data. It is even possible to generate a script to do this automatically. Documentation can be found here.
Once you have accieved this, you can just look at your importated mat file and modify it to your wish. (for example adding a line in your textfile) And once you are done, you can save it as a textfile again.
Kind regards, Christiaan
  1 件のコメント
Ionut  Anghel
Ionut Anghel 2015 年 6 月 17 日
It si not really working. The follow errors occures: Error using file>normalize (line 316) Directory of \\pnap1h1\ita\MATLAB\PI636_2HCP_Plot.txt doesn't exist Error in file (line 106) answer = normalize(arg); Error in finfo (line 13) fil=file('normalize',varargin{1});
The directory exist and file is read with fopen, and I can write with fprintf. My files are really big (above 100 MB). I needed to rewrite to a specific format in order to use a special plot program. Thank you for your kindness,
Ionut

Community Treasure Hunt

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

Start Hunting!

Translated by