필터 지우기
필터 지우기

how to separate columns from txt file

조회 수: 10 (최근 30일)
Venkatkumar M
Venkatkumar M 2022년 11월 17일
댓글: David Hill 2022년 11월 17일
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.
Could anyone please help me to resolev the issue?

채택된 답변

Stephen23
Stephen23 2022년 11월 17일
M = readmatrix('r4.4u_db.txt', 'TrimNonNumeric',true, 'Delimiter',{'\t',','})
M = 6178×3
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

추가 답변 (2개)

David Hill
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
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
dpb 2022년 11월 17일
Use the force, uh, er, detectImportOptions, @Venkatkumar M...
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

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by