read data from serial port , change to number and plot it

8 visualizaciones (últimos 30 días)
Truong
Truong el 19 de Mayo de 2014
Respondida: María el 19 de Mayo de 2014
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 comentario
Star Strider
Star Strider el 19 de Mayo de 2014
You posted numbers. What does the array look like that contains both numbers and characters?

Iniciar sesión para comentar.

Respuestas (1)

María
María el 19 de Mayo de 2014
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

Categorías

Más información sobre Low-Level File I/O 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!

Translated by