Extract certain value from a string

4 vues (au cours des 30 derniers jours)
James Lorringer
James Lorringer le 17 Sep 2015
Commenté : James Lorringer le 17 Sep 2015
Hello, i got this text file in the form like:
Concentrations of Certain Solutions
Conc. %SD Solution
4.394 9% Asdf
2.804 14% Yxcv
1.630 23% Qwer
Now I want to extract the second value from the third line without % symbol: 14.
How can I do this? I know I should use textscan function, but do not know how to continue. Can some one help me on this?
P.S. suppose the name of the file is just FileName, so the first line like
fid = fopen(FileName, 'rt');
could be used.
Thanks a lot!

Réponse acceptée

Walter Roberson
Walter Roberson le 17 Sep 2015
fid = fopen(FileName, 'rt');
datacell = textscan(fid, '%*f%f', 1, 'HeaderLines', 2);
sd = datacell{1};
  1 commentaire
James Lorringer
James Lorringer le 17 Sep 2015
Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (1)

Thorsten
Thorsten le 17 Sep 2015
fid = fopen('FileName.txt');
D = textscan(fid, '%f %f%%%s', 'Headerlines', 1);
fclose(fid)
value = D{2}(2);
  1 commentaire
James Lorringer
James Lorringer le 17 Sep 2015
Thanks, it also works!

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by