Import .txt file and write to txt file

1 vue (au cours des 30 derniers jours)
Frank Oosterveld
Frank Oosterveld le 2 Oct 2020
Commenté : Ameer Hamza le 2 Oct 2020
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 commentaires
Frank Oosterveld
Frank Oosterveld le 2 Oct 2020
Any idea which is more efficient than with the tables as you proposed?
Ameer Hamza
Ameer Hamza le 2 Oct 2020
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by