How to add system date & time in x axis of a plot, corresponding to a real-time measurement
Show older comments
Hi,
Im using an arduino to send some measurments to matlab using usb. As you can see on the code below, im making a plot of that data. I use real-time drawing of the plot adding each new measurement instantly. Measurements appear on the y axis while the number of each measurement appears on the x axis. I want to keep the number of each measurement in x (because this way i can control how many points will appear on the plot). Although, i need to make the system date and time (dd.mm hh:mm) corresponding to each measurement appear instead of the numbers, somehow using xticks i guess. I'm having some trouble doing this. Thanks in advance!
Heres my code:
clear all
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
clc
baud = 115200;
arduino=serial('COM23','BaudRate',baud);
fopen(arduino);
x=linspace(1,1000000,1000000);
y=zeros(1,1000000);
i=0;
j=1;
points=60;
y1=0;y2=17000000;
while (true)
i = i+1;
if (i > points)
j = i - points;
end
y(i) = fscanf(arduino, '%d');
plot(x,y,'-r','LineWidth',1.5)
axis([x(j) x(i+1) y1 y2])
title('Plot','FontSize',16,'Color','r')
grid on
grid minor
ylabel('Measurement','FontSize',12,'FontWeight','Bold')
xlabel('# of Measurement','FontSize',12,'FontWeight','Bold')
drawnow
end
Accepted Answer
More 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!