Import .txt file and write to txt file
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
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 Exchange で Workspace Variables and MAT Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!