在MATLAB中将多个2D图堆叠到单个3D图中 [英] Stacking multiple 2D plots into a single 3D plot in MATLAB

查看:684
本文介绍了在MATLAB中将多个2D图堆叠到单个3D图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个FFT图,我想在一个图中一起显示它们,就像附图所示.

I have multiple FFT plots and I want to show them together in one plot, something like the attached figure.

我不知道如何开始.任何帮助将不胜感激!

I don't have any clue how to start. Any help would be appreciated!

推荐答案

做起来还不错.您可以使用 plot3 来帮助您进行这种绘图.使用plot3,您需要做的是将每个图的y值改为z值,如果要分离图形,则需要更改此3D图中的y值. .让我们做一个例子.假设我想以这种方式在一个绘图上放置4个图形.这些图形是:

That's not so bad to do. You can use plot3 to help you facilitate this kind of plotting. With plot3, what you need to do is make the y values for each of your plots z values instead, and if you want to separate the graphs, you need to vary the y values in this 3D plot. Let's do an example. Let's say I want to place 4 graphs on a single plot in that fashion. The graphs are:

  • y = sin x
  • y = cos x
  • y = exp(-x)*sin(x)
  • y = exp(-x)*cos(x)
  • y = sin x
  • y = cos x
  • y = exp(-x)*sin(x)
  • y = exp(-x)*cos(x)

这样,您将获得一组x值,每个值都相同.您将拥有一组y值,这些值将有所不同,并且取决于图本身.您将这些值设置为z值,然后对于每个图形,您将拥有不同的y值,但是对于每个图,它们的 all 都将相同,就像您将想要使用它们来相应地偏移每个图形以将它们分开.因此:

As such, you'll have a set of x values that are the same for each of the plots. You'll have a set of y values that are going to be different, and is dependent on the graph itself. You'll make these the z values, then for each of these graphs, you'll have different y values, but for each plot they will all be the same, as you'll want to use these to offset each of your graphs accordingly to separate them. As such:

%// Define the x values
x = (0:0.001:10).';
xMat = repmat(x, 1, 4); %// For plot3

%// Define y values
y = 0:0.001:0.003;
yMat = repmat(y, numel(x), 1); %//For plot3

%// Define z values
z1 = sin(x);
z2 = cos(x);
z3 = exp(-x).*sin(x);
z4 = exp(-x).*cos(x);
zMat = [z1 z2 z3 z4]; %// For plot3

plot3(xMat, yMat, zMat, 'b'); %// Make all traces blue
grid;
xlabel('x'); ylabel('y'); zlabel('z');
view(40,40); %// Adjust viewing angle so you can clearly see data

这是我得到的数字:

诀窍是形成正确的矩阵,以便正确地将其放入plot3. plot3的工作方式是您可以为x,y,z值放置单个向量,或者可以使用矩阵 xMat,yMat,zMat代替. xMatyMatzMat的每个矩阵的每一列表示要放置在绘图中的单个迹线.因此,每个信号的xMat的每一列都进入单个列.这样,我为我的x值创建了一个一个向量,并复制了它们以获取尽可能多的信号.在这种情况下,我们有4个信号. y值将必须以不同的方式播放.您需要弄清楚在每个信号之间允许有多少 spacing .我为每个信号选择了0.001.这样,我就创建了一个矩阵,该矩阵存储在yMat中,并且每一列代表00.0010.0020.003. z值将是放置在我用zMat创建的不同列中的每个信号的y值.

The trick is to form the right matrices so that this goes into plot3 correctly. How plot3 works is that you can either place single vectors in for your x,y,z values, or you can use matrices xMat,yMat,zMat instead. Each column of each matrix of xMat, yMat and zMat denote a single trace to be placed in your plot. Therefore, each column of xMat for each signal goes into a single column. As such, I created one vector for my x values, and replicated them over for as many signals as we have. In this case, we have 4 signals. The y values will have to be played with differently. You need to figure out how much spacing is going to be allowed for in between each signal. I chose 0.001 for each signal. As such, I've created that matrix, which is stored in yMat, accordingly and each column represents either 0, 0.001, 0.002 or 0.003. The z values are going to be your y values for each signal placed in different columns, which I created with zMat.

您需要试着获得每个轴的正确间距和正确边界,但这应该可以帮助您入门.祝你好运!

You'll need to play around with this to get the right spacing and the right bounds of each axes, but this should get you started. Good luck!

这篇关于在MATLAB中将多个2D图堆叠到单个3D图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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