reading text and reformatting for excel
Show older comments
Another member of my team has created a modelling programme which outputs data that looks like this:
Train MWh consumed MWh regen V_av. Umean_tr Min V @ km Max V Max Delay(s) @ station
01_02_01 0.2498 -0.0209 1.5755 1.474 1.1937 0.027523 1.8
01_02_02 0.2496 -0.0259 1.5717 1.4722 1.1937 0.027523 1.7963
01_02_03 0.2496 -0.0277 1.569 1.4723 1.1937 0.027523 1.7963
01_02_04 0.2494 -0.0299 1.5628 1.4614 1.1938 0.027523 1.798
01_02_05 0.2497 -0.0299 1.5628 1.4621 1.1941 0.027523 1.7974
01_02_06 0.2497 -0.0299 1.5628 1.4621 1.1941 0.027523 1.7974
01_02_07 0.2497 -0.0299 1.5628 1.4621 1.1941 0.027523 1.7974
01_02_08 0.2497 -0.0299 1.5628 1.4621 1.1941 0.027523 1.7974
01_02_09 0.2497 -0.0299 1.5628 1.4621 1.1941 0.027523 1.7974
01_02_10 0.2497 -0.0299 1.5628 1.4621 1.1941 0.027523 1.7974
01_02_11 0.2497 -0.0296 1.5629 1.4621 1.1941 0.027523 1.7985
01_02_12 0.2497 -0.0272 1.5691 1.4646 1.1941 0.027523 1.8
I want to read the 'table' and reformat it into excel. Is that likely to be simple or should I delve into the depths of his programme and print them to the excel sheet directly?
11 Comments
Stephen23
on 16 Jun 2026
"outputs data that looks like this"
Where? In the command window, in a UITABLE, in a text file, or somewhere else?
Mathieu NOE
on 16 Jun 2026
if the native file is ascii , txt , etc... you can open directly from within excel , why use matlab in the loop (unless you can complex math to perform ?)
It rather depends: if you want to write smelly, one-time code that requires manual steps then feel free to process the results from DIARY or the command window. If you want the more generalised approach then modify the code to write to file directly using WRITETABLE or WRITECELL or similar.
Mathieu NOE
on 16 Jun 2026
the data is output in the command window
then why not save it directly to a file with appropriate format - instead of using diary where all history of the command window can be annoying ?
if you would post such a diary file and say what you need / want , we may better help you (btw)
Timothy
on 19 Jun 2026
If this is a requirement of the app it would seem to work with the developer to merge into the base code, then. Otherwise, you'll still be reinventing the wheel to parse a changed output format.
ADDENDUM
Even if all you can convince him/her to do is to output a distinct keyword surrounding specific output sections of interest it would make parsing consistent and easy to add/remove sections instead of having to search for some format/title that may either change or have multiple instances to isolate the section of interest from or any other of an innumerable number of possibilites....and I've had to do much of that in the past on occasion and it ain't always fun nor trivial.
Timothy
on 22 Jun 2026
dpb
on 22 Jun 2026
Glad to help guide if can...try parsing ANSYS output files of thousands of pages with headers, page numbers, different output options requested by user, etc., etc., ... <grin> ... been there done that and sometimes it is the only way, but it's almost never as trivial as it seems going in.
Timothy
on 23 Jun 2026
dpb
on 23 Jun 2026
If this is, as sounds as if is, a continuing need, the upfront effort will undoubtedly pay longterm beneifts.
Accepted Answer
More Answers (0)
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!