brainReader
brainReader

Reputation: 143

Plotting multiple graphs in a single window by using matlab

I'm trying to make matlab record live data from muse headset and I'm successful to plot accelerometer data and voltage v/s time data in a single window. if I try to add new graph for the same window, then the new graph will overlap with the existing code.

Here is a part of code which deals with plotting of graphs.

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(2,1,2);
         time = 0:1/fsa:secBuffer-1/fsa;
         h2= plot(time,accBuffer);
         xlabel('Time (s)')
         ylabel('Acceleration (mG)')
         legend(h2, accName, 'Location','EastOutside');

         subplot(2,1,3);
         final = eegBuffer*5;
         h3 = plot(final,eegBuffer);
         xlabel('final')
         ylabel('eegbuffer')
         %legend(h2, accName, 'Location','EastOutside');

         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);  

And here is the screen shot:
screen shot

Upvotes: 1

Views: 843

Answers (1)

Ander Biguri
Ander Biguri

Reputation: 35525

You are using subplot(2,1,X). If you read the documentation, the first two numbers are rows and colums of the "plot matrix", therefore, you are defining a plot matrix of 2x1=2 subplots.

If you want to plot 3 things you should change the subplot lines to:

subplot(2,2,1)  

subplot(2,2,2)

subplot(2,2,3)  % or subplot(2,2,3:4) for even more fancy ploting

Upvotes: 5

Related Questions