How to plot 3 different values in single plot in real time.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Cedric
2013-2-16
编辑:Cedric
2013-2-16
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]) ;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!