使用Matlab在单个窗口中绘制多个图形 [英] Plotting multiple graphs in a single window by using matlab

查看:740
本文介绍了使用Matlab在单个窗口中绘制多个图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使Matlab记录来自缪斯耳机的实时数据,并且我成功地在单个窗口中绘制了加速度计数据和电压v/s时间数据.如果我尝试为同一窗口添加新图形,则新图形将与现有代码重叠.

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:

推荐答案

您正在使用subplot(2,1,X).如果您阅读了文档,则前两个数字是行和因此,您要定义一个2x1 = 2个子图的图矩阵.

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.

如果要绘制3幅图,则应将子图线更改为:

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

这篇关于使用Matlab在单个窗口中绘制多个图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆