Get only one value from Arduino to Matlab using fscanf

3 views (last 30 days)
Hello everyone, I want to send data from Arduino to Matlab and Matlab back to Arduino. Because I use interrupt so I have to use Serial seperately in Arduino and Matlab There are code I learn from the Internet to send data from Arduino to Matlab In Matlab:
arduino=serial('COM4','BaudRate',9600);
fopen(arduino);
y=fscanf(arduino,'%f');
fclose(arduino);
And in Arduino:
float temperature=9.100;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(temperature);
}
But when I run the program in Matlab, I saw that y had many different values, sometimes y was a char array. I just want to get one value, so how can I do that? Thank you very much!

Answers (0)

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!