How to extract certain values from text file to find average of the group of numbers?
3 views (last 30 days)
Show older comments
Sujata Dhar
on 10 Sep 2021
Commented: Star Strider
on 11 Sep 2021
Can you please help me to extract certain column of numbers from a text file. I want to find their average. The following .txt file is as follows. I want only # 25 to 30 sigma values.
Number of unknowns: 1374
Number of observations: 28854 of 28854
Number of constraints: 1246
Number of datum stations: 14
Number of datum sources: 0
vTPv: 67100.6 +/- 1944.94
redundancy: 28726
chi^2: 1.5282 +/- 0.0220971
List of estimated parameters
.----------------------------------------------------------------------------------------------------.
| # | Type | member | reference epoch | sigma [unit] | repeatability [unit] |
|-------|-----------|----------|---------------------|-----------------------|-----------------------|
| 0 | PWL_CLK | AGGO | 2021.05.18 17:00:00 | 0.62888 [cm] | 1.99957 [cm] |
| 1 | PWL_CLK | AGGO | 2021.05.18 18:00:00 | 0.91947 [cm] | 4.93553 [cm] |
| 2 | PWL_CLK | AGGO | 2021.05.18 19:00:00 | 1.64927 [cm] | 8.35032 [cm] |
| 3 | PWL_CLK | AGGO | 2021.05.18 20:00:00 | 2.28501 [cm] | 10.70383 [cm] |
| 4 | PWL_CLK | AGGO | 2021.05.18 21:00:00 | 2.92039 [cm] | 12.11574 [cm] |
| 5 | PWL_CLK | AGGO | 2021.05.18 22:00:00 | 3.51718 [cm] | 12.86139 [cm] |
| 6 | PWL_CLK | AGGO | 2021.05.18 23:00:00 | 4.05227 [cm] | 12.85490 [cm] |
| 7 | PWL_CLK | AGGO | 2021.05.19 00:00:00 | 4.56631 [cm] | 12.34585 [cm] |
| 8 | PWL_CLK | AGGO | 2021.05.19 01:00:00 | 5.02033 [cm] | 11.29844 [cm] |
| 9 | PWL_CLK | AGGO | 2021.05.19 02:00:00 | 5.44759 [cm] | 10.22204 [cm] |
| 10 | PWL_CLK | AGGO | 2021.05.19 03:00:00 | 5.82947 [cm] | 9.16751 [cm] |
| 11 | PWL_CLK | AGGO | 2021.05.19 04:00:00 | 6.17638 [cm] | 8.30392 [cm] |
| 12 | PWL_CLK | AGGO | 2021.05.19 05:00:00 | 6.49624 [cm] | 7.89360 [cm] |
| 13 | PWL_CLK | AGGO | 2021.05.19 06:00:00 | 6.79364 [cm] | 7.92088 [cm] |
| 14 | PWL_CLK | AGGO | 2021.05.19 07:00:00 | 7.06446 [cm] | 8.59745 [cm] |
| 15 | PWL_CLK | AGGO | 2021.05.19 08:00:00 | 7.30998 [cm] | 9.59593 [cm] |
| 16 | PWL_CLK | AGGO | 2021.05.19 09:00:00 | 7.55144 [cm] | 10.44086 [cm] |
| 17 | PWL_CLK | AGGO | 2021.05.19 10:00:00 | 7.77601 [cm] | 11.36565 [cm] |
| 18 | PWL_CLK | AGGO | 2021.05.19 11:00:00 | 8.00764 [cm] | 11.76791 [cm] |
| 19 | PWL_CLK | AGGO | 2021.05.19 12:00:00 | 8.24088 [cm] | 11.82715 [cm] |
| 20 | PWL_CLK | AGGO | 2021.05.19 13:00:00 | 8.49287 [cm] | 11.09234 [cm] |
| 21 | PWL_CLK | AGGO | 2021.05.19 14:00:00 | 8.76043 [cm] | 9.66000 [cm] |
| 22 | PWL_CLK | AGGO | 2021.05.19 15:00:00 | 9.06284 [cm] | 7.28851 [cm] |
| 23 | PWL_CLK | AGGO | 2021.05.19 16:00:00 | 9.41047 [cm] | 4.15836 [cm] |
| 24 | PWL_CLK | AGGO | 2021.05.19 17:00:00 | 9.75290 [cm] | 1.99957 [cm] |
| 25 | PWL_CLK | HART15M | 2021.05.18 17:00:00 | 0.57717 [cm] | 1.75935 [cm] |
| 26 | PWL_CLK | HART15M | 2021.05.18 18:00:00 | 0.88342 [cm] | 4.97802 [cm] |
| 27 | PWL_CLK | HART15M | 2021.05.18 19:00:00 | 1.59244 [cm] | 8.59066 [cm] |
| 28 | PWL_CLK | HART15M | 2021.05.18 20:00:00 | 2.26089 [cm] | 10.78367 [cm] |
| 29 | PWL_CLK | HART15M | 2021.05.18 21:00:00 | 2.90160 [cm] | 12.28015 [cm] |
| 30 | PWL_CLK | HART15M | 2021.05.18 22:00:00 | 3.49047 [cm] | 13.06497 [cm] |
| 31 | PWL_CLK | HART15M | 2021.05.18 23:00:00 | 4.03382 [cm] | 13.11746 [cm] |
| 32 | PWL_CLK | HART15M | 2021.05.19 00:00:00 | 4.54147 [cm] | 12.73883 [cm] |
| 33 | PWL_CLK | HART15M | 2021.05.19 01:00:00 | 5.00205 [cm] | 11.97155 [cm] |
| 34 | PWL_CLK | HART15M | 2021.05.19 02:00:00 | 5.42749 [cm] | 10.89467 [cm] |
| 35 | PWL_CLK | HART15M | 2021.05.19 03:00:00 | 5.81582 [cm] | 9.73427 [cm] |
0 Comments
Accepted Answer
Star Strider
on 10 Sep 2021
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/734899/Sujata%20Dhar%20%20text%20file%20-%202021%2009%2010.txt', 'VariableNamingRule','preserve');
sigma = regexp(T1{:,6}, '\d*.\d*[^[cm]]','match');
T2 = table(T1{:,2}, str2double([sigma{:}]).', 'VariableNames',{'#','sigma'})
sigma_25to30 = T2.sigma(25:30)
or possibly —
sigma_25to30 = T2.sigma(T1.('#')>=25 & T2.('#')<=30)
I have no idea if this will work with the original text file because it never actually appeared as an uploaded/attached file. If there is a problem with it, use the one supplied here instead, since it works with my code.
Experiment to get different results.
.
4 Comments
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown 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!