Reading numeric value from COM port
1 回表示 (過去 30 日間)
古いコメントを表示
I try to use fscanf( ) to get the numeric heading of an electronic compass. The compass is sending data through COM1 with NMEA standard. When I open the port, and use FSCANF(ser) I get
ans =
$HCHDG,49.0,,,,
My problem is: how to filter the 49.0 out of this string, and convert it to a numeric value (eg float) so I can use it for calculations?
0 件のコメント
回答 (1 件)
Walter Roberson
2011 年 10 月 15 日
textscan(). Or fscanf() or sscanf(). Or strfind() and index to extract the number as a string and str2double() it. Or regexp() to extract the number as a string and str2double() it.
A format of '%*7c' would eat the '$HCHDG,' and discard it.
2 件のコメント
Walter Roberson
2011 年 10 月 15 日
Sorry, I am not familiar enough with simulink. I am sure there is _some_ way, but I do not know if there is a "nice" way.
参考
カテゴリ
Help Center および File Exchange で Standard File Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!