필터 지우기
필터 지우기

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

조회 수: 8 (최근 30일)
Truong
Truong 2014년 5월 19일
답변: María 2014년 5월 19일
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
Star Strider 2014년 5월 19일
You posted numbers. What does the array look like that contains both numbers and characters?

댓글을 달려면 로그인하십시오.

답변 (1개)

María
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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by