Picking out stage coordinates using sscanf
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Stephen23
2015 年 10 月 12 日
編集済み: Stephen23
2015 年 10 月 12 日
>> 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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!