Borrar filtros
Borrar filtros

How to read iiregular mixed numeric and string data

12 visualizaciones (últimos 30 días)
Jeongpyo Lee
Jeongpyo Lee el 3 de Abr. de 2017
Comentada: Jayaram Theegala el 6 de Abr. de 2017
Hi, I have a complex text file as below(it is same with attached file). It is mixed with string and numeric columns, also one of them is irregular data with mixed string and numeric as the "mdata" column. I want to read all the data as a matrix variable from this formatted file. How can I do this?
num1 num2 str1 num3 str2 mdata num4 str3
1 2 AB 3 4CD005 6.1234 11 EF
1 2 GH 0 4CD005 IJ -11 EF
1 3 KL 2 4CD005 -7.3456 11 MN
2 1 OP 3 4CD005 2.0001 11 QR
2 3 ST 1 4CD005 -10.6789 -11 UV

Respuestas (1)

Jayaram Theegala
Jayaram Theegala el 5 de Abr. de 2017
As KSSV has suggested, you can use the "readtable" command as shown below to read the data from your file as a table:
readtable('complex_data.txt')
For more information about "readtable", click on the following URL:
  2 comentarios
Jeongpyo Lee
Jeongpyo Lee el 6 de Abr. de 2017
Thank you, Jayaram. Then How do I calculate with elements in the table? For example, If I read the file using readtable.m as a variable(t=readtable('complex_data.txt')), I want to calculate t(2,1)+t(2,2).
Jayaram Theegala
Jayaram Theegala el 6 de Abr. de 2017
You can access the individual elements in the table, by using the column names. For instance, if column names are "num1" and "num2", you can add the second row, first two column elements as follows:
t.num1(2) + t.num2(2)
For more information about using "Tables" in MATLAB, click on the following URL:

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by