How to read iiregular mixed numeric and string data

조회 수: 20 (최근 30일)
Jeongpyo Lee
Jeongpyo Lee 2017년 4월 3일
댓글: Jayaram Theegala 2017년 4월 6일
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
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
Jeongpyo Lee
Jeongpyo Lee 2017년 4월 6일
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 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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by