Matlab only receives 1 arduino data
Show older comments
I want to graph some data that comes from arduino to matlab but, I only graph 1 data from the series of data that I have, why? thank you very much for reading me
<<<<<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>>>>>>><<
function Matlab_Arduino
close all;
clc;
y=zeros(1,1000); %Vector donde se guardaran los datos
%Inicializo el puerto serial que utilizare
delete(instrfind({'Port'},{'COM13'}));
puerto_serial=serial('COM13');
puerto_serial.BaudRate=9600;
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
%Abro el puerto serial
fopen(puerto_serial);
figure('Name','Serial communication: Matlab + Arduino')
title('SERIAL COMMUNICATION MATLAB+ARDUINO');
xlabel('time');
ylabel('aceleration');
grid on;
hold on;
%graph
ylim([0 100]);
xlim([0 100]);
aceleracion=fscanf(puerto_serial,'%d');
plot(aceleration,'X-r');
fclose(puerto_serial);
delete(puerto_serial);
clear all;
end
Accepted Answer
More Answers (1)
Use readline instead of fscanf command
3 Comments
Walter Roberson
on 4 Feb 2025
The question involved use of serial() objects. As of R2025a pre-release, serial() objects are still supported (but are due to be removed any day now.)
serial() objects do not have a readline() method, so fscanf() or fgetl() are still the appropriate functions for serial() objects.
Oscar
on 4 Feb 2025
But so far it's easier., thanks for your comment.
Walter Roberson
on 4 Feb 2025
If you construct a serial() object, then readline() applied to the serial() object is simply not defined.
serial() objects are not recommended, having been functionally replaced by serialport() objects. readline() is defined for serialport() objects.
Categories
Find more on Serial and USB Communication 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!