Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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 Comments
Bob Thompson
Bob Thompson on 8 Mar 2019
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
Edited: David André Gomez Romero on 9 Mar 2019
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.

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!