read data from serial port , change to number and plot it
8 次查看(过去 30 天)
显示 更早的评论
I'm working on a project that uses serial port to receive data, save to a variable so that I can process it later. I used fscanf command to achieve it and receive a large string but not numbers :
x=fscanf(s) %s is serial port name
x=
58514
58954
59386
59799
60207
60683
...
44598
45193
45809
46431
OK %1024 elements
I expect an array with 1024 elements but all I get is a very large string with both numbers and characters inside it. My question is whether I can use any command instead of fscanf, or how I can get only numbers (double or integer, not char) from that string. Thanks a lot
1 个评论
Star Strider
2014-5-19
You posted numbers. What does the array look like that contains both numbers and characters?
回答(1 个)
María
2014-5-19
Try to read the data like this:
x=fgets(s)
It will give you just one line (once you read it, it will give you the following line). Then, you can use the function str2num() to convert the string to a number
y=str2num(x)
I hope this works for you
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!