Textscan skipping character 'd'
Afficher commentaires plus anciens
So I have this string:
fileName ='Br0HAA2dSJ_752012_1.gcd'
And I want to use textscan to extract the 0, HAA, 2, and d in separate cells
DepVar =textscan(fileName,'Br %f %[THAMS] %d %c');
but in the last cell (DepVar{1,4}) it returns a 'S' instead of the 'd' that I want. What is going on and how do I fix it?
Thanks,
Sid
Réponse acceptée
Plus de réponses (1)
per isakson
le 20 Juil 2012
Modifié(e) : per isakson
le 20 Juil 2012
Try:
DepVar = textscan( fileName, 'Br%u%[THAMS]%d%c%*s' );
.
--- Response to comment ---
I cannot reproduce the behavior you see, i.e. "S", with textscan (R2012a - the only one I have installed). However,
cac = cell(1,4);
[cac{:}] = strread( file_name, 'Br%f%[THAMS]%f%c%*s' )
cac =
[0] {1x1 cell} [2] 'S'
Note the "S".
strread is a predecessor of textscan (and I guess textscan is partly based on old code used by strread).
I have not checked the bug database. I propose you report this as a bug.
.
--- In response to Walters answer ---
This might work. However, the number of digits must be known and the item is returned as a string and must be converted: str2double.
DepVar = textscan( file_name, 'Br%f%[THAMS]%1[1234567890]%c%*s' )
4 commentaires
Sid
le 20 Juil 2012
per isakson
le 20 Juil 2012
It returns "0, HAA, 2, and d" with your particular sample string under R2012a. What do you mean by "doesn't work"?
Sid
le 20 Juil 2012
per isakson
le 20 Juil 2012
Did you consider using REGEXP?
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!