在matlab中重叠轴

时间:2014-10-15 08:44:46

标签: matlab plot

我创建了2个轴来绘制来自设备的实时EEG信号。我得到2个信号,一个是eegBuffer,另一个是FFT。

以下是代码:

 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

由于我获得了2个实时信号,我使用2个轴来绘制这2个实时信号。然而,这些轴重叠。这是屏幕截图: screen shot

您可以清楚地看到2个轴重叠。我该如何解决?

1 个答案:

答案 0 :(得分:1)

要创建子图,您需要使用subplot(是的,我有点多余)功能。

您需要按以下方式为每个子图调用它:

subplot( No. of subplot rows , No. of subplot columns, subplot number)

因此,如果你想绘制两件事,一件在另一件之上,你需要调用它:

subplot(2,1,1)
% plot you rthings
subplot(2,1,2)
%plot your second things

有关详细信息,请参阅documentation