Import .txt file and write to txt file

1 回表示 (過去 30 日間)
Frank Oosterveld
Frank Oosterveld 2020 年 10 月 2 日
コメント済み: Ameer Hamza 2020 年 10 月 2 日
hi,
I have a file, Force_inputt.txt, which I want to read, change one value and write it back, this is how I did it so far:
Where I chose to import the .txt file by use of data import, use enough spacespacespace... delimiters and save it as a table.
Forceinput = importfile1('Force_input.txt', 1, inf)
Forceinput.VarName3(end,1) = 5
writetable(Forceinput,'Force_test.txt')
This works, however, then I get a messy file:
VarName1,LOADS,VarName3,VarName4,VarName5,VarName6
"**","LOADS",NaN,,,
"**","",NaN,,,
"**","Name:",-1,Type:,Concentrated,force
"*Cload","",NaN,,,
"Set-7,","2,",5,,,
Instead, I just want to write it back to the clean file, such as this:
** LOADS
**
** Name: Load-1 Type: Concentrated force
*Cload
Set-7, 2, -0.5
any recommendations??
  4 件のコメント
Frank Oosterveld
Frank Oosterveld 2020 年 10 月 2 日
Any idea which is more efficient than with the tables as you proposed?
Ameer Hamza
Ameer Hamza 2020 年 10 月 2 日
Tables are useful when data is properly organized in columns, each column containing data of a similar type. You data following a custom formatting. For such cases, reading text, using sscanf(), textscan(), strrep(), regexp(), etc are more useful.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by