Choose specific values from dataset

I have the following dataset consisting of two columns, interrupted by random integers. How can I read the dataset (attached below) and keep only the first set of values (colored red in the picture) after each integer?

 採用された回答

Stephen23
Stephen23 2022 年 5 月 4 日
編集済み: Stephen23 2022 年 5 月 4 日

1 投票

txt = fileread('demodata1.txt');
rgx = '^\s+\d+\s+(\S+)\s+(\S+)';
tkn = regexp(txt,rgx,'tokens','lineanchors');
mat = str2double(vertcat(tkn{:}))
mat = 4×2
0.3164 -0.3921 -0.1385 0.4998 0.4545 -0.2000 -0.1175 -0.1774

1 件のコメント

Jorg Borren
Jorg Borren 2022 年 5 月 4 日
It works, thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by