Reputation: 1595
I created 2 axes for plotting live EEG signals from a device. And I'm getting 2 signals, one is eegBuffer and another one is FFT.
Here is the code:
if eegCounter == 44
if plot1
axes;
%subplot(2,1,1);
time = 0:1/fse:secBuffer-1/fse;
h1 = plot(time,eegBuffer);
legend(eegName, 'Location','EastOutside');
xlabel('Time (s)')
ylabel('Voltage (uV)')
%subplot(3,1,2);
%time = 0:1/fsa:secBuffer-1/fsa;
%h2= plot(time,accBuffer);
%xlabel('Time (s)')
%ylabel('Acceleration (mG)')
%legend(h2, accName, 'Location','EastOutside');
%legend(h2, accName, 'Location','EastOutside');
%This code deals with fft calculations
%w = axis;
%subplot(2,1,2);
%Fse = 220;
%T = 1/Fse;
%time = 0:1/fse:secBuffer-1/fse;
%x = eegCounter;
%y = eegBuffer;
%NFFT = 2^nextpow2(eegCounter);
%Y = fft(y,NFFT)/eegCounter;
%f = Fse/2*linspace(0,1,NFFT/2+1);
%xlabel = ('frequency(Hz)');
%ylabel = ('|y(f)|');
%h2 = plot(f,2*abs(Y(1:NFFT/2+1)));
plot1 = false;
else
cell1 = (num2cell(eegBuffer,1))';
set(h1,{'ydata'},cell1);
%cell2 = (num2cell(accBuffer,1))';
%set(h2,{'ydata'},cell2);
%cell3 = (num2cell(final,1))';
%set(h3,{'ydata'},cell3);
end
axes;
%subplot(2,1,2);
Fse = 220;
T = 1/Fse;
time = 0:1/fse:secBuffer-1/fse;
x = eegCounter;
y = eegBuffer;
NFFT = 2^nextpow2(eegCounter);
Y = fft(y,NFFT)/eegCounter;
f = Fse/2*linspace(0,1,NFFT/2+1);
xlabel = ('frequency(Hz)');
ylabel = ('|y(f)|');
h2 = plot(f,2*abs(Y(1:NFFT/2+1)));
plot2 = false;
%plot3 = false;
drawnow;
eegCounter = 0;
end % if eegCounter
Since I'm getting 2 live signals, I'm using 2 axes to plot those 2 live signals. However those axes get overlapped. Here is the screen shot:
You can clearly see that 2 axes are overlapping. How can I fix it?
Upvotes: 0
Views: 803
Reputation: 35525
To create subplots, you need to use the subplot
(yeah, Im a bit redundant) function.
You need to call it for each subplot in the following way:
subplot( No. of subplot rows , No. of subplot columns, subplot number)
Therefore if you want to plot 2 things, one in top of the other, you need to call it:
subplot(2,1,1)
% plot you rthings
subplot(2,1,2)
%plot your second things
See documentation for more information
Upvotes: 1