Hello,
I have the matlab version 2018a.
I'm trying to extract specific columns of a text file based on the header name of the column. I have tried couple of different methods such as readtable, textscanf, etc. but, none of them exactly worked as I expected.
I have attached the text file itself. I'm trying to make sure the code I'm writing is not slow because there are 1000's of these files that I need to look into in a for-loop possibly.
The structure never changes but, the header columns can be in different positions and that's the reason why I want the code to find the header name no matter which position the column is in.
Here is a sample from the text file:
As it can be seen, the same dates are repeated below with different headers (information) and it is repeated 3-4 times in the actual text file. If I know how to pick up "WOPR – PROD1", "WOPR-PROD2", and "FOPT" columns and put them into a matrix in this order [WOPR-PROD1; WOPR-PROD2; FOPT] I can figure out the rest I believe. I prefer not to modify the text file itself if possible.
"--------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""SUMMARY OF RUN Original_1 "--------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""DATE ""YEARS ""FOPR ""FWPR ""FGPR ""FOPT ""FGPT ""FWPT ""FWCT ""FWIR "" ""YEARS ""STB/DAY ""STB/DAY ""MSCF/DAY ""STB ""MSCF ""STB "" ""STB/DAY "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""--------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------"" 1JAN2009" 0 0 0 0 0 0 0 0 0 " 1FEB2009" 0.084873 0 0 0 0 0 0 0 0 " 1MAR2009" 0.161533 2000.000 65.16867 1360.000 56000.00 38080.00 1824.723 0.031556 0 " 1APR2009" 0.246407 2000.000 67.93040 1360.000 118000.0 80240.00 3906.001 0.032849 0 " 1MAY2009" 0.328542 2449.850 53.91752 1665.898 191495.5 130216.9 5523.527 0.021535 0 "--------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""SUMMARY OF RUN Original_1 ""--------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""DATE ""FWIT ""FGOR ""FOIP ""FWIP ""FGIP ""FPR ""WOPR ""WOPR ""WOPR "" ""STB ""MSCF/STB ""STB ""STB ""MSCF ""PSIA ""STB/DAY ""STB/DAY ""STB/DAY "" "" "" ""*10**3 ""*10**3 ""*10**3 "" "" "" "" "" "" "" "" "" "" "" ""PROD1 ""PROD2 ""PROD3 "" "" "" "" "" "" "" "" "" "" ""--------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------""-----------"" 1JAN2009" 0 0 31190.54 645456.1 21209.57 6553.930 0 0 0 " 1FEB2009" 0 0 31190.54 645456.1 21209.57 6553.922 0 0 0 " 1MAR2009" 0 0.680000 31134.54 645454.2 21171.49 6473.267 0 0 0 " 1APR2009" 0 0.680000 31072.54 645452.2 21129.33 6394.598 0 0 0 " 1MAY2009" 0 0.680000 30999.18 645450.7 21079.44 6296.722 0 1675.190 0
Any help is appreciated. Thank you.
Best Answer