how to separate columns from txt file
조회 수: 25 (최근 30일)
이전 댓글 표시
Hi,
I have attached a txt file needed to be delimeter by 3 columns.
Txt file looks like this
Freq. V(n001)
2.00000000000000e+001 (6.52532088670673e+001dB,-8.99982757383219e+001°)
2.00461047615580e+001 (6.52332088670214e+001dB,-8.99982770536383e+001°)
Need the output to looks like this with delimeter
2.00000000000000e+001 6.52532088670673e+001 -8.99982757383219e+001°
Especially the third column must be in degree fromat.
I have tried this code
clc;
clear all;
c = readtable("r4.4u_db.txt",'Format','%f %*c %f %*s %*c %f %*s');
But the 3rd column is totataly different like this
20.0461047615580
20.1386333770361
20.2315890851980
20.3249738574139
Don't know why does it show like that.
And aslo suggest a method to convert the dB vaues to linear values
The output plot from txt should look like attached photo.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1196748/image.jpeg)
Could anyone please help me to resolev the issue?
댓글 수: 0
채택된 답변
Stephen23
2022년 11월 17일
M = readmatrix('r4.4u_db.txt', 'TrimNonNumeric',true, 'Delimiter',{'\t',','})
댓글 수: 0
추가 답변 (2개)
David Hill
2022년 11월 17일
Try:
c = readtable("r4.4u_db.txt",'Format','%f %*c %f %*c%*c%*c %f %*c%*c');
댓글 수: 1
David Hill
2022년 11월 17일
What is your reference value to computing dB? Very easy to convert to linear.
Linear=10.^(c.Var2/10)*refValue;
dpb
2022년 11월 17일
opt=detectImportOptions('r4.4u_db.txt','NumHeaderLines',1,'Delimiter',{',',\t}, ...
'ExpectedNumVariables',3,'TrimNonNumeric',1);
tM=readmatrix('r4.4u_db.txt',opt);
results in
>> whos tM
Name Size Bytes Class Attributes
tM 6178x3 148272 double
>> tM(1:10,:)
ans =
20.0000 65.2532 -89.9983
20.0461 65.2332 -89.9983
20.0923 65.2132 -89.9983
20.1386 65.1932 -89.9983
20.1851 65.1732 -89.9983
20.2316 65.1532 -89.9983
20.2782 65.1332 -89.9983
20.3250 65.1132 -89.9983
20.3718 65.0932 -89.9983
20.4188 65.0732 -89.9983
>>
as for the latter Q?, db2mag
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!