Read value from a text file and store into an array

I have a text file 'Busdata8.txt' which has data as follows:
%|Bus | Type | Vsp | theta | PGi | QGi | PLi | QLi | Qmin | Qmax | Transaction |
1 1 1.0 0 0 0 0 0 0 0 1
2 2 1.03 0 550 0 0 0 0 0 1
3 3 1.0 0 0 0 350 0 0 0 1
4 3 1.0 0 0 0 300 0 0 0 1
5 3 1.0 0 0 0 250 0 0 0 1
6 3 1.0 0 0 0 100 0 0 0 2
7 3 1.0 0 0 0 100 0 0 0 3
8 2 1.05 0 100 0 0 0 0 0 2
8 2 1.05 0 100 0 0 0 0 0 3
I want to skip the wordings in the first line and extract the numerical data into an array, something look like this:
Array = 1 1 1.0 0 0 0 0 0 0 0 1
2 2 1.03 0 550 0 0 0 0 0 1
3 3 1.0 0 0 350 0 0 0 0 1
4 3 1.0 0 0 300 0 0 0 0 1
5 3 1.0 0 0 250 0 0 0 0 1
6 3 1.0 0 0 100 0 0 0 0 2
7 3 1.0 0 0 100 0 0 0 0 3
8 2 1.05 0 100 0 0 0 0 0 2
8 2 1.05 0 100 0 0 0 0 0 3
Kindly help me out. Thanks in advance.

 Respuesta aceptada

Stephen23
Stephen23 el 21 de Feb. de 2018
Editada: Stephen23 el 21 de Feb. de 2018
Use dlmread:
>> M = dlmread('BusData8.txt','',1,0)
M =
1.00000 1.00000 1.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000
2.00000 2.00000 1.03000 0.00000 550.00000 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000
3.00000 3.00000 1.00000 0.00000 0.00000 0.00000 350.00000 0.00000 0.00000 0.00000 1.00000
4.00000 3.00000 1.00000 0.00000 0.00000 0.00000 300.00000 0.00000 0.00000 0.00000 1.00000
5.00000 3.00000 1.00000 0.00000 0.00000 0.00000 250.00000 0.00000 0.00000 0.00000 1.00000
6.00000 3.00000 1.00000 0.00000 0.00000 0.00000 100.00000 0.00000 0.00000 0.00000 2.00000
7.00000 3.00000 1.00000 0.00000 0.00000 0.00000 100.00000 0.00000 0.00000 0.00000 3.00000
8.00000 2.00000 1.05000 0.00000 100.00000 0.00000 0.00000 0.00000 0.00000 0.00000 2.00000
8.00000 2.00000 1.05000 0.00000 100.00000 0.00000 0.00000 0.00000 0.00000 0.00000 3.00000

Más respuestas (0)

Etiquetas

Preguntada:

el 21 de Feb. de 2018

Editada:

el 21 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by