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!