remove variables in txt file

1 view (last 30 days)
Venkatkumar M
Venkatkumar M on 7 Apr 2020
Commented: Ilian on 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?

Accepted Answer

Ilian
Ilian on 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 Comment
Ilian
Ilian on 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));

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!