Re-organize LS-DYNA data from text file removing header and footer
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Davide De Cicco
am 20 Okt. 2016
Kommentiert: Davide De Cicco
am 27 Okt. 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:
and I'd like to have it like this
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 Kommentare
Akzeptierte Antwort
Sam McDonald
am 25 Okt. 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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!