extract numbers from text file

2 次查看(过去 30 天)
YUE
YUE2022-8-14
评论: YUE ,2022-8-14
Hello, I have a text file that contains a series of lines as following form, but I only need the number data here, so how can I just read/import numbers from TXT files?
sub_name sub_id gender RT keypress cond
wangweiliang 103 1 9.138582e+00 4 5
wangweiliang 103 1 3.183194e+00 8 2
wangweiliang 103 1 2.689366e+00 1 1
wangweiliang 103 1 4.470684e+00 9 8
wangweiliang 103 1 3.016167e+00 4 4
wangweiliang 103 1 4.793164e+00 3 3
wangweiliang 103 1 2.943291e+00 1 6
wangweiliang 103 1 2.798679e+00 3 7

回答(1 个)

Chunru
Chunru 2022-8-14
T = readtable("data.txt");
T=T(:, 2:end)
T = 8×5 table
sub_id gender RT keypress cond ______ ______ ______ ________ ____ 103 1 9.1386 4 5 103 1 3.1832 8 2 103 1 2.6894 1 1 103 1 4.4707 9 8 103 1 3.0162 4 4 103 1 4.7932 3 3 103 1 2.9433 1 6 103 1 2.7987 3 7
x = table2array(T)
x = 8×5
103.0000 1.0000 9.1386 4.0000 5.0000 103.0000 1.0000 3.1832 8.0000 2.0000 103.0000 1.0000 2.6894 1.0000 1.0000 103.0000 1.0000 4.4707 9.0000 8.0000 103.0000 1.0000 3.0162 4.0000 4.0000 103.0000 1.0000 4.7932 3.0000 3.0000 103.0000 1.0000 2.9433 1.0000 6.0000 103.0000 1.0000 2.7987 3.0000 7.0000

Community Treasure Hunt

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

Start Hunting!

Translated by