Import numeric data from mixed txt file

1 次查看(过去 30 天)
Hello everybody,
I'd like to import only the numeric data in the attached txt file, so all lines containing '#', '##' or '**' should be ignored. I tried the textscan function, but it only seems to support one character as parameter for CommentStyle. What would be the easiest solution to read only the numeric data?
I
Thank you very much for your help!

回答(1 个)

Chunru
Chunru 2022-5-23
a = readtable('data.txt', 'CommentStyle', '#')
a = 6480×31 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 Var16 Var17 Var18 Var19 Var20 Var21 Var22 Var23 Var24 Var25 Var26 Var27 Var28 Var29 Var30 Var31 ____ ________ ________ ____ __________ ___________ ________ ___________ ____ _____ _______ ________ ________ _________ ___________ _______ ___________ _____ _____ ________ ___________ _______ __________ _____ _____ _________ ___________ _______ ___________ _____ _____ 1 0.15056 0.97102 0 0.33299 7.4973e-19 0.051952 1.4862e-19 0 0 0.24436 0.42363 0.36585 0.24436 4.9618e-19 0 0 0 0 0.42363 1.009e-18 0 0 0 0 0.33099 7.4401e-19 0.15586 4.4585e-19 0 0 2 0.028868 0.65 0 -0.0072999 1.1565e-18 1.1085 2.0031e-18 0 0 1.1088 1.0959 1.1212 -0.0219 3.4694e-18 1.1085 2.0031e-18 0 0 0 0 1.0959 4.0062e-18 0 0 0 0 1.1212 0 0 0 3 0.028868 0.55 0 0.0017048 -5.7824e-19 1.1507 3.0046e-18 0 0 1.1508 1.1537 1.1478 0.0051145 -1.7347e-18 1.1507 3.0046e-18 0 0 0 0 1.1537 2.0031e-18 0 0 0 0 1.1478 4.0062e-18 0 0 4 0.028868 0.45 0 0.010521 1.1565e-18 1.14 2.3111e-33 0 0 1.1405 1.1583 1.1218 0.031563 3.4694e-18 1.14 0 0 0 0 0 1.1583 2.0031e-18 0 0 0 0 1.1218 -2.0031e-18 0 0 5 0.65 0.028868 0 0.25784 5.0077e-19 0.049789 2.8912e-19 0 0 0.29798 0.1716 0.34407 0.25784 5.0077e-19 0.14937 8.6736e-19 0 0 0.1716 0 0 0 0 0 0.34407 1.0015e-18 0 0 0 0 6 0.030332 0.24903 0 0.030547 0 0.93588 0 0 0 0.9384 0.98722 0.88651 0.09164 0 0.93392 0 0 0 0 0 0.98722 0 0 0 0 0 0.88651 0 0 0 7 0.028978 0.15053 0 0.042608 5.7541e-19 0.7574 1.0033e-18 0 0 0.76964 0.83015 0.68311 0.12782 1.7262e-18 0.75895 1.0242e-18 0 0 0 0 0.83015 1.9857e-18 0 0 0 0 0.68311 0 0 0 8 0.033333 0.033333 0 0.10322 0 0.10322 0 0 0 0.30965 0.30965 0 0.30965 0 0 0 0 0 0 0 0.30965 0 0 0 0 0 0 0 0 0 9 0.96667 0.96667 0 0.1033 0 0.1033 0 0 0 0 0.30989 0.30989 0 0 0 0 0 0 0.30989 0 0 0 0 0 0 0 0.30989 0 0 0 10 0.033333 0.96667 0 -0.081597 0 0.081597 0 0 0 0.24479 0.24479 0 0 0 0.24479 0 0 0 -0.24479 0 0 0 0 0 0 0 0 0 0 0 11 0.85365 0.97058 0 -0.16927 -2.5442e-19 0.059724 1.3952e-19 0 0 0.25688 0.26337 0.060357 -0.18408 -2.8903e-19 0.17917 4.1856e-19 0 0 -0.26337 -4.7424e-19 0 0 0 0 -0.060357 0 0 0 0 0 12 0.75155 0.96946 0 -0.078265 0 0.057031 0 0 0 0.19063 0.16873 0.018009 -0.084071 0 0.17109 0 0 0 -0.16873 0 0 0 0 0 0.018009 0 0 0 0 0 13 0.65 0.97113 0 0.0037847 1.2519e-19 0.053205 7.228e-20 0 0 0.15966 0.08837 0.095939 0.0037847 1.2519e-19 0.15962 2.1684e-19 0 0 -0.08837 0 0 0 0 0 0.095939 2.5039e-19 0 0 0 0 14 0.35 0.028868 0 0.0041578 0 0.053046 0 0 0 0.15919 0.08772 0.096035 0.0041578 0 0.15914 0 0 0 -0.08772 0 0 0 0 0 0.096035 0 0 0 0 0 15 0.45 0.97113 0 0.18071 -2.5039e-19 0.050457 -1.4456e-19 0 0 0.23573 0.093315 0.2681 0.18071 -2.5039e-19 0.15137 -4.3368e-19 0 0 0.093315 0 0 0 0 0 0.2681 -5.0077e-19 0 0 0 0 16 0.35 0.97113 0 0.25775 -5.0077e-19 0.049937 -2.8912e-19 0 0 0.29812 0.17125 0.34424 0.25775 -5.0077e-19 0.14981 -8.6736e-19 0 0 0.17125 0 0 0 0 0 0.34424 -1.0015e-18 0 0 0 0

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by