Re-organize LS-DYNA data from text file removing header and footer
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Davide De Cicco
el 20 de Oct. de 2016
Comentada: Davide De Cicco
el 27 de Oct. de 2016
Hello,
I'm trying to extract data from an LS-DYNA output text file and write it into a new file with a new format, but I find the initial format a bit complicated and I have problem getting what I want, which is:
- Header: keep the same (LS-DYNA keyword ... date)
- One line with the legend of the data, with timestep and time moved to columns 1 and 2, respectively (two new columns should be created)
- N lines with the actual data
- No footer
The starting file looks like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157312/image.png)
and I'd like to have it like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157313/image.png)
From that point I can use textscan to manipulate the data the way I want.
Numpy library in Python has the command genfromtxt that allows to remove header and footer, then choose which data to extract from a specific column of a specific line. I couln't find such a command in MATLAB, and i tried with a combination of, fgets, fgetl, and textscan, but impossible to achieve what I'm looking for.
Does anyone have an idea of which function would work best?
Thanks a lot!
0 comentarios
Respuesta aceptada
Sam McDonald
el 25 de Oct. de 2016
I understand that you would like to know what MATLAB functions would work best to format your data so it can be easily imported using textscan.
Because your original data file is not formatted the same on each line, you will likely need to call 'fgetl' to read in each line as a character array. Use 'eof' to determine when the end of the file has been reached.
To extract the numerical values from lines that contain many characters, you can first remove the characters by using the 'replace' function.
Then, you can use 'textscan' on the remaining string to extract the numerical values.
Once you have read the data into MATLAB, you can use a function like 'fprintf' to write the data to another file.
These functions should help you write custom code to achieve the desired format.
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Text 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!