Getting values from balance into matlab

조회 수: 2 (최근 30일)
Marianne Hull-Cantillo
Marianne Hull-Cantillo 2021년 2월 4일
답변: Les Beckham 2021년 2월 4일
I am trying to get values from my balance into matlab to be plotted over time. I am using the following functions
>> s = serial('COM4', 'BaudRate', 9600);
>> fopen(s);
>> a = fscanf(s)
I get the following:
a =
'S S 98.98g
'
In the workspace it appears as a [name] and 1x18 char [value]
How can I convert the value 'S S 98.98g' to a number variable?

답변 (1개)

Les Beckham
Les Beckham 2021년 2월 4일
Try this:
number = sscanf(a, '%*c %*c %f%*c');
The * characters tell sscanf to ignore (not return) those fields. You can learn more in the documentation here: https://www.mathworks.com/help/matlab/ref/sscanf.html

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by