Info

此问题已关闭。 请重新打开它进行编辑或回答。

Write a txt-file from a specific value in another txt-file

1 次查看(过去 30 天)
Hello everyone,
I'm having some issues in order to write a txt-file from another txt-file. I want to supresse some part of the original txt-file and write only the essential information that I need. For exemple, in the original-txt file I have :
----------------------------------------------------------------------------------------------------------------------------------------------------
<Thelen2003Muscle name="Ps_L1_VB_r">
<!--The set of points defining the path of the muscle.-->
<GeometryPath>
<!--The set of points defining the path-->
<PathPointSet>
<objects>
<PathPoint name="PathPoint_lumbar1">
<location> -0.00057725 0.029429 0.02</location>
<body>lumbar1</body>
</PathPoint>
<PathPoint name="PathPoint_pelvis">
<location> -0.0238 -0.057 0.0759</location>
<body>pelvis</body>
</PathPoint>
</objects>
<groups />
</PathPointSet>
----------------------------------------------------------------------------------------------------------------------------------------------------
I want to write in my new txt-file, only the information of location, for exemple in my new txt-file I need :
----------------------------------------------------------------------------------------------------------------------------------------------------
<location> -0.00057725 0.029429 0.02</location>
<location> -0.0238 -0.057 0.0759</location>
----------------------------------------------------------------------------------------------------------------------------------------------------
I think I have to use fpintf, but my problem is to say : read from here to here and write this information here.
Thanks in advance, Dave.
  2 个评论
Bob Thompson
Bob Thompson 2019-3-8
Do you have any code written already? How are you choosing to load the file? Generally, with text files it is simplest to just read the entire file and then parse what you want from there.
David André Gomez Romero
编辑:David André Gomez Romero 2019-3-9
Thanks Bob for the reply.
But I found the solution of my problem, like txt-file is in fact an XML. I juste use the function : xml2struct (found here : https://ch.mathworks.com/matlabcentral/fileexchange/58700-xml2struct-with-bug-fix-and-added-features).
I obtains a well structure in MatLab and I juste have to choose the information that I need in the structure to write it in my new txt-file.

回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by