How to read numbers from a txt file with numbers and text

3 ビュー (過去 30 日間)
Sergio RUGGIERI
Sergio RUGGIERI 2020 年 5 月 16 日
コメント済み: Image Analyst 2020 年 5 月 17 日
Hi there,
I have a txt file as the attached one.
I want to read only the numbers, in order to elaborate after the data into a matrix.
I'm trying with this code, but it does not work, cause it does not read the last columns.
path1='.../path1'
fid = fopen(path1);
data = textscan(fid,'%s%f%f%f%f%s%s%f%f','HeaderLines',1,'CollectOutput',1);
data = data{1,1};
fid = fclose(fid);
Can anyone help me? Thanks in advance

採用された回答

Image Analyst
Image Analyst 2020 年 5 月 16 日
Try readtable():
t = readtable('example.txt')
data = t(:, [1:4,11,12])
  2 件のコメント
Sergio RUGGIERI
Sergio RUGGIERI 2020 年 5 月 17 日
Thanks for the suggestion. It works!
After, through the command "table2array(data)" I can jump to matrix.
Image Analyst
Image Analyst 2020 年 5 月 17 日
There is a table2array() function if you want to convert the table to a matrix.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by