Hello! Everyone
I want to plot the temperature data coming from serial port per second and time_stamp it in MATLAB, and display the time information on X-Axis.
The data coming from serial port is in string format and after receiving it, i converted it into double and plotted using MATLAB plot function. But i am not able to understand, that how can i time stamp the received data and mention that time on x-axis.
Currently i created a circular array of 100 values, which will be increased later to show more information. My program is as follow:
delete(instrfind)
ser = serial('COM5', 'BaudRate',9600, 'Timeout',10);
DATA_SIZE = 100;
temperature = zeros(DATA_SIZE, 1);
index = 1;
fopen(ser);
while true
temp = fscanf(ser);
if size(temp) == [0][0]
disp 'Timeout Occurs'
disp 'Check Connections'
break
else
if index < DATA_SIZE
index = index+1;
else
index = 1;
end
temperature(index) = str2double(temp);
plot(temperature, 'LineWidth',2,'Color',[0,0,1.0])
ylim([0,80])
xlabel('Time \rightarrow')
ylabel('Temperature (C)\rightarrow');
title('Real-Time Temperature Plot');
drawnow
end
end
fclose(ser);
I tried to plot the time value on X-Axis but failed to get the correct output. Please someone help me regarding this. Any other suggestion are also welcomed. Thanks in advance.