Import .txt file and write to txt file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Ameer Hamza
el 2 de Oct. de 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!