Azzera filtri
Azzera filtri

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

8 visualizzazioni (ultimi 30 giorni)
Truong
Truong il 19 Mag 2014
Risposto: María il 19 Mag 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 Commento
Star Strider
Star Strider il 19 Mag 2014
You posted numbers. What does the array look like that contains both numbers and characters?

Accedi per commentare.

Risposte (1)

María
María il 19 Mag 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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by