Azzera filtri
Azzera filtri

remove variables in txt file

1 visualizzazione (ultimi 30 giorni)
Venkatkumar M
Venkatkumar M il 7 Apr 2020
Commentato: Ilian il 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?

Risposta accettata

Ilian
Ilian il 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 Commento
Ilian
Ilian il 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));

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by