How to read iiregular mixed numeric and string data
14 次查看(过去 30 天)
显示 更早的评论
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
回答(1 个)
Jayaram Theegala
2017-4-5
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 个评论
Jayaram Theegala
2017-4-6
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!