I am trying to simulate a real time plot of an ECG signal using MATLAB GUI. For testing purposes I am trying to implement a sine wave that plots as if in real time. I am using a GUI with one button which starts plotting the sine wave, and a set of axes tagged as 'axes1'. The code below is extracted from the callback function for the start button:
%create a sine wave to plot
X=[0:0.1:25*pi];
X=transpose(X);
Y=sin(X);
[a,b] = size(X);
hold on;
%initialise axes limits
axis(handles.axes1,[0,a,-1,1]);
%plot sine wave
for i = 1:a
plot(handles.axes1,1:i,Y(1:i));
drawnow;
pause(0.01);
end
The result is a moving sine wave, but I am trying to define the axes limits beforehand so that they don't keep re-sizing as the wave is plotted. I have tried using the line
axis(handles.axes1,[0,1,-1,1])
To set the axes limits but it is not working as I would like it to and I'm not sure how to proceed from this point.
Thanks in advance for any help!
Set the ...LimMode
properties to manual during the axes creation; that way they should not change when new data are plot. By default they are set at auto
.
Eg:
set(handles.axes,'XLimMode','manual','YLimMode','manual');