Import text + data txt file into a matrix

7 ビュー (過去 30 日間)
Michele Rizzato
Michele Rizzato 2020 年 9 月 20 日
コメント済み: Michele Rizzato 2020 年 9 月 25 日
Good morning to all.
I have a complex txt file semicolon separated with both strings and numbers.
I wish to get a matrix to manipulate the content and operate matricial calculus in it.
Any idea how to operate?
I copy first two rows of the matrix here below but the overall file is more than 5000 rows.
Each row is divided in 15 columns (some of them empty). Just columns 3 4 5 10 12 13 are numbers, all the rest can be text.
Thank you very much
Michele
905856340;TRIAL1;00151250;00151250;00151250;0009;CASE1;1322;PROOF1;00002;7AA1A01;22;00125000;5021791709151;;
913769511;TRIAL2;00009150;00009150;00009150;0009;CASE2;1392;PROOF2;00002;7AC2C;22;00003230;5021791708536;;
  2 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 9 月 22 日
You can use either readtable or textscan
Michele Rizzato
Michele Rizzato 2020 年 9 月 25 日
Thank you Mr. Sami, that was very helpful!

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

回答 (1 件)

Madhav Thakker
Madhav Thakker 2020 年 9 月 23 日
Hi Michele,
I understand that you want to read your data where each entry is separated by ';' and each row is separated by ';;'. readtable can be used to read data from text files into a matrix.
opts = detectImportOptions('yourTextFile.txt')
opts parameters can be changed to fit custom text files. You might want to look at Delimiter, LineEnding, VariableTypes to fit your needs.
opts.LineEnding = {';;'};
table = readtable('yourTextFile.txt', opts)
Hope this helps.
  1 件のコメント
Michele Rizzato
Michele Rizzato 2020 年 9 月 25 日
Thank you Madhav!

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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by