how to separate columns from txt file

24 Ansichten (letzte 30 Tage)
Venkatkumar M
Venkatkumar M am 17 Nov. 2022
Kommentiert: David Hill am 17 Nov. 2022
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?

Akzeptierte Antwort

Stephen23
Stephen23 am 17 Nov. 2022
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

Weitere Antworten (2)

David Hill
David Hill am 17 Nov. 2022
Try:
c = readtable("r4.4u_db.txt",'Format','%f %*c %f %*c%*c%*c %f %*c%*c');
  1 Kommentar
David Hill
David Hill am 17 Nov. 2022
What is your reference value to computing dB? Very easy to convert to linear.
Linear=10.^(c.Var2/10)*refValue;

Melden Sie sich an, um zu kommentieren.


dpb
dpb am 17 Nov. 2022
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

Kategorien

Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by