## MATLAB: How to plot live data from arduino on current HH:MM x axis

hh:mmlive datareal time

I can plot live data however I am now trying to plot on an x axis that reflects the time of day that the data was recorded. I have had an attempt (seen below) can anyone see why it isn’t working or know how to achieve my task?

`%User Defined Properties `

a = arduino('Com3') % define the Arduino Communication port

plotTitle = 'Solar Data Log'; % plot title

xLabel = 'Elapsed Time (s)'; % x-axis label

yLabel = 'Power (W)'; % y-axis label

yMax = 5.5 %y Maximum Value

yMin = 0 %y minimum Value

plotGrid = 'on'; % 'off' to turn off grid

min = 0; % set y-min

max = 5.5; % set y-max

delay = 1; %Define Function Variables

elapsed_hours = delay*60;elapsed_min = delay;t_1 = [08, 00]; % Start time 08:00

t_2 = [t_1(1) + elapsed_hours, t_1(2) + elapsed_min*60]; % End time 10:30

HH_1 = t_1(1); % Hour digits of t_1

MM_1 = t_1(2); % Minute digits of t_1

HH_2 = t_2(1); % Hour digits of t_2

MM_2 = t_2(2); % Minute digits of t_2

time = HH_1/24+MM_1/1440:1/1440:HH_2/24+MM_2/1440%time = 0;

data = 0;count = 0;%Set up Plot

plotGraph = plot(time,data,'-r' ) % every AnalogRead needs to be on its own

Plotgraphdatetick('x','HH:MM')hold on %hold on makes sure all of the channels are

plottedtitle(plotTitle,'FontSize',15);xlabel(xLabel,'FontSize',15);ylabel(yLabel,'FontSize',15);axis([yMin yMax min max]);grid(plotGrid);ticwhile ishandle(plotGraph) %Loop when Plot is Active will run until plot is closed

Vin = readVoltage(a,'A0'); Vout = readVoltage(a,'A1'); Vin = Vin*5.00501002 *1.789; Vout; Power = Vin * Vout; dat = Power %Data from the arduino

count = count + 1; time(count) = toc; data(count) = dat(1); %This is the magic code

%Using plot will slow down the sampling time.. At times to over 20

%seconds per sample!

set(plotGraph,'XData',time,'YData',data); axis([0 time(count) min max]); %Update the graph

pause(delay);end

## Best Answer