Filter löschen
Filter löschen

remove variables in txt file

1 Ansicht (letzte 30 Tage)
Venkatkumar M
Venkatkumar M am 7 Apr. 2020
Kommentiert: Ilian am 7 Apr. 2020
Hi guys,
I have trouble in removing first line in txt file, remove () , in txt file and split into three vectors.
fnm1 = 'p_s.txt ';
E = load(fnm1);
t=E(:,1);
v=E(:,2);
someone plese help me out?

Akzeptierte Antwort

Ilian
Ilian am 7 Apr. 2020
You could remove the header line first with something like this:
fileID = fopen('p_s.txt');
dataFormat = '%f %s';
C_text = textscan(fileID,dataFormat,'HeaderLines',1,'Delimiter','\t');
t = cell2mat(C_text(1));
And then use regexp to get the numerical values from the second column
  1 Kommentar
Ilian
Ilian am 7 Apr. 2020
There is for sure a better solution to this, but If you just want something that works, you can just add a few extra delimiters
fileID = fopen('p_s.txt');
dataFormat = '%f (%f %s %s %f %s';
C_text = textscan(fileID,dataFormat,'HeaderLines',1,'TreatAsEmpty',{'d'},'Delimiter','\tdB,)');
t1 = cell2mat(C_text(1));
t2 = cell2mat(C_text(2));
t3 = cell2mat(C_text(5));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by