简体   繁体   English

在Matlab中用冲浪重建3D图形?

[英]Reconstruct 3D graph with surf in matlab?

I usually use surf function to plot 3D figures in matlab, but now the data is different, so I am using plot3 and I have the below figure. 我通常使用surf函数在matlab中绘制3D图形,但是现在数据有所不同,因此我使用plot3并且具有以下图形。 Do you have any idea how I reconstruct this figure to be more understandable even if by using different function. 您有任何想法,即使使用不同的功能,我如何将这个数字重构为更易于理解。 To be more concise, I have X values, with each X value there is a value of Y and value of Z. 简而言之,我有X值,每个X值都有一个Y值和Z值。

在此处输入图片说明

X = [ 1 ;2 ;4; 8; 16; 32; 64];
Z = [ 1; 1.8 ; 3.46 ; 6.74 ; 13.18 ; 24.34 ; 39.33]
Y = [0 ; 56.92 ; 91 ; 109.95 ; 119 ; 123.57 ; 125.51]
fig = plot3(log(X),Y,Z,'b.-');
XLABEL=[  1 2 4 8 16 32 64];
set(gca,'XTickLabel',XLABEL);
set(gca,'XTick',log(XLABEL));

YLABEL= [ 0 30 60 90 120 150 180];
set(gca,'YTickLabel',YLABEL);
set(gca,'YTick',YLABEL);

ZLABEL= [0 5 10 15 20 25 30 35 40 45 50 55];
set(gca,'ZTickLabel',ZLABEL);
set(gca,'ZTick',(ZLABEL));
ylim([0 180]);
zlim([0,55]);

grid on

It's difficult to say, because we don't have a context. 很难说,因为我们没有上下文。 Common options are: 常见选项有:

  1. Plotting x/y and x/z in two separate plots. 在两个单独的图中绘制x / y和x / z。 Precisely readable but difficult to get the connection between y and z. 精确可读,但很难获得y和z之间的联系。 subplot 插曲
  2. Plotyy, same as previous but in one plot. 积,与以前相同,但在一个积中。 Y and Z values which correspond to the same x-value are aligned. 对应于相同x值的Y和Z值对齐。 plotyy plotyy
  3. Use a plot3 as shown above, but connect each point to the x/z plane. 如上所示使用plot3,但是将每个点连接到x / z平面。 (details below) (详情如下)
  4. Project the line on one or multiple planes and draw it there. 将线投影到一个或多个平面上并在此处绘制。 (Plot the line again, setting x, y or z to 7 0 or 180, which is the location of your axis) (再次绘制该线,将x,y或z设置为7 0或180,这是轴的位置)
  5. If two axis are of major importance, use a simple 2d plot and represent the third dimension using color/dotsize/annotations etc... 如果两个轴非常重要,请使用简单的2d图并使用颜色/点大小/注释等表示第三维。

Code for Option 3: 选项3的代码

At the end of your code, add the following code: 在代码末尾,添加以下代码:

X2=[X';X';nan(size(X'))];
X2=X2(:);
Y2=[Y';Y';nan(size(Y'))];
Y2=Y2(:);
Z2=[Z';zeros(size(Z'));nan(size(Z'))];
Z2=Z2(:);

hold on
plot3(log(X2),Y2,Z2,'--')

To understand it, you have to know that matlab skips nans while plotting. 要了解它,您必须知道matlab在绘制时会跳过nans。 Thus the code above generates a independent line segment for each point, connecting it to the ground plane. 因此,上面的代码为每个点生成一个独立的线段,并将其连接到接地平面。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM