remove variables in txt file

1 vue (au cours des 30 derniers jours)
Venkatkumar M
Venkatkumar M le 7 Avr 2020
Commenté : Ilian le 7 Avr 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?

Réponse acceptée

Ilian
Ilian le 7 Avr 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 commentaire
Ilian
Ilian le 7 Avr 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));

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by