Picking out stage coordinates using sscanf
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jason
el 12 de Oct. de 2015
Hi, I have a string where X&Y stage coordiantes are concatenated together with a comment.
-1042,7953**Tile1
so X=-1042, Y=7953, Comment=Tile1
I've trying to use sscanf to decompose these back to X, Y and comment:
num=sscanf(txtline, '%f,%f%s')
However its not appearing to give me what I need. Perhaps the occurance of the minus sign is messing things up. The problem is, is that either of the numbers can be positive or negative (positive appears with no prefix, negative appears with a '-').
Thanks for any advice
0 comentarios
Respuesta aceptada
Stephen23
el 12 de Oct. de 2015
Editada: Stephen23
el 12 de Oct. de 2015
>> A = sscanf('-1042,7953**Tile1','%f,%f**%s');
>> X = A(1)
X = -1042
>> Y = A(2)
Y = 7953
>> C = char(A(3:end).')
C = Tile1
The trick is to read the sscanf documentation, and in particular this line: "If the format includes: ... A combination of numeric and character specifiers, A is numeric, of class double. MATLAB converts each character to its numeric equivalent."
This mans the first two values are the numeric values in your string, and the rest are the character values. We simply convert these values back to character to get the comment string.
The negative sign - or a positive sign + does not cause any problems for sscanf, because the format %f recognizes both of these signs.
Más respuestas (0)
Ver también
Categorías
Más información sobre Numeric Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!