How to read a table in a txt file that contains many irrelevant text and symbols

1 visualizzazione (ultimi 30 giorni)
Hi,
I am pretty new to Matlab and I could not figure this out on my own, thus I would appreciate if someone could help me out.
I have a text file which contains a lot of texts and symbols in it and I only want to read a table 4 out from it. I have tried to use readtable but it did not work. I've attached part of my file below:
===================================
EXERCISE
SYSTEM__________: OS (L)
ARCHITECTURE______: X_64 WIN 10 /MACOX
PYTHON /MATLAB: SYSTEM X32
===================================
THERE ARE SOME INSTRUCTION ON THIS EXERCISE ...
VERSION.rv2192
TABLE 1XXX 8
X------------X----X-------X------X------X------X------X
SUBSISTEMA No Inic. Sem_01 Sem_02 Sem_03 Sem_04
X------------X----X-------X------X------X------X------X
S 1 65.1 67.2 69.1 70.5 71.5
E 2 44.9 50.7 54.4 55.4 55.3
N 3 95.8 97.3 97.3 96.5 96.2
W 4 100.0 88.6 96.1 98.7 98.9
X------------X----X-------X------X------X------X------X
TABLE 4 (abax)
X---X------------X----X---X---X---X---X------X------X-----X-------X------X------X------X------X-------X-------X-------X-------X-------X-X
Num Nome Ssis Pos Usi Usi Usi Volume Volume Vutil Previs Pinst Perdas Qtur Qdef Vert Produt Somprd Produt Somprd T
da Usina Vaz Jus Des Jus Maximo Minimo Inic Oper Hid Maxima Minima Maximo Eqv Eqv 65% VU 65% VU I
Ope Ope Ene hm3 hm3 % MW % - M m3/s m3/s m3/s MJ/m3 MJ/m3 MJ/m3 MJ/m3 P
X---X------------X----X---X---X---X---X------X------X-----X-------X------X------X------X------X-------X-------X-------X-------X-------X-X
1 ANFJINSG DK 1 2 0 2 792. 120. 99.0 ABR2022 46. 0.1 m 245. 0. 0.1E+21 0.1880 6.1355 0.2076 6.2465 M
2 HSNBGUFF DK 2 4 0 4 11. 11. 0.0 ABR2022 52. 0.6 m 213. 0. 0.1E+21 0.2437 5.9475 0.2437 6.0389 D
4 IJKLNGMRANDE DK 211 6 0 6 266. 266. 0.0 ABR2022 180. 0.4 m 507. 0. 0.1E+21 0.3549 5.7038 0.3549 5.7952 D
24 JNGHYTACAO DK 24 31 0 31 17725. 4669. 65.6 ABR2022 1192. 1.0 m 1094. 0. 0.1E+21 1.0893 4.4103 1.1582 4.5334 M
27 CNHYT BRANC1 DK 207 28 0 28 241. 228. 100.0 ABR2022 240. 1.8 m 470. 0. 0.1E+21 0.5104 4.2484 0.5114 4.3035 M
28 CHNBG BRANC2 DK 28 31 0 31 868. 868. 0.0 ABR2022 210. 0.5 m 504. 0. 0.1E+21 0.4169 3.7380 0.4169 3.7921 D
readtable('Test1.txt', 'Delimiter', 'X')

Risposte (1)

Harsha Kalavakolu
Harsha Kalavakolu il 13 Mag 2022
Hello Aria
I understand you want to read a part of the text file into MATLAB. As I can see, you have tried the "readtable" function, however, this cannot be achieved with a single line of code as there is no proper format/pattern available in this case. You must write a script to read this file partly according to your needs. "textscan" is one of the functions that can be useful to you in this case.
For more information on textscan you can go through the documentation https://www.mathworks.com/help/matlab/ref/textscan.html
Or
You can try using the data import tool from the “User Interface” that will let you select an area to import from the file manually but still as there are many unwanted characters in the file you must manually remove them.
Hope it helps

Categorie

Scopri di più su Text Analytics Toolbox in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by