How to plot 3 different values in single plot in real time.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Here i need to read data from serial port, for plotting ECG waveform in real time. From that serial data, i need to create 2 more values. like serial data=x
1st value=x; 2nd value=x-50; 3rd value=x-20;
so for these 3 values i need to add different colors ('r','g','b') in single plot that to in real time.
In below code i can able to receive one value from serial port and plotted in real time.
obj = serial('COM1','BaudRate',9600); %creating the object
fopen(obj); %open port
set(obj,'terminator','cr') %providing the terminator
a1=0; % a variable for y axis
time1=now; % time is in x axis
liH=line(NaN,NaN);
while 1 % infinite loop
time2=now;
x=[time1 time2];
ip_data = fscanf(obj);
a2= str2num(ip_data) ;
a=[a1 a2];
line(x,a);
set(liH,'XData',[get(liH,'XData') x]);
set(liH,'YData',[get(liH,'YData') a]);
datetick('x','HH:MM') %change the axis
% pause(0.5);
a1=a2;
time1=time2;
end
delete(instrfindall)
Here i am plotting correctly for single value, then how to change colors of each value and how to plot 3 different values in single plot.
Any suggestions please..?
Thank You
0 comentarios
Respuesta aceptada
Cedric
el 16 de Feb. de 2013
Editada: Cedric
el 16 de Feb. de 2013
Using hold on allows you to plot consecutively on the same figure without erasing the previous content. E.g.
figure(1) ;
clf ;
hold on ;
plot(sin(0:.1:10), 'r') ;
plot(cos(0:.1:10), 'g') ;
I don't fully understand why you want to change the color for each line, but you can do this using the ColorSpec parameter, generating the RGB triple with some mathematical function of your own:
line([0, 100], [-1, 1], 'Color', [1,0.4,0]) ;
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!