如何绘制3D图在MATLAB? [英] How to plot a 3D plot in MATLAB?

查看:267
本文介绍了如何绘制3D图在MATLAB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个参数 X T 。但问题是我的文件结构。

我的文件命名为:

  e_x_y.txt
t_x_y.txt
 

其中, e_x_y.txt 已为 X Ÿ特定值的误差 t_x_y.txt 有相应的时间值。

我需要绘制出 X VSŸVS牛逼图中的 e_x_y.txt 的值

什么是做到这一点的最好方法是什么?

我知道x和y的值都,所以我没有从文件名中扣除他们。


为了让事情更清晰,

想我的文件是:

  e_4_5.txt
45
54
t_4_5.txt
2.0
6

e_7_8.txt
32
98
121
t_7_8.txt
2
9
1.0
 

我想绘制以下几点:

 (4,5,2.0)= 45
(4,5,6.0)= 54
(7,8,2.0)= 32
(7,8,9.0)= 98
(7,8,1.0)= 121
 

解决方案

剧情你正试图使可能很难看到很好的类型。我可以给你两个建议:一个是你的需要的,一个是你应该做的可能不是......

绘图四维数据:

为了做到这一点,你必须绘制了一系列 X,Y,T 点,并以某种方式重新present误差值ê在每个点。可以通过改变点的颜色或大小做到这一点。在本实施例中,我将绘制球体在每个点的直径而变化的基础上的误差(直径为1相当于最大预期误差)。再$ P $颜色psents的时间。我将使用您添加​​到问题的样本数据(格式为 5×4 矩阵包含 X 列, T 电子数据):

 数据= [4 5 2 45; 4 5 6 54; 7 8 2 32; 7 8 9 98; 7 8 1 121];
[X,Y,Z] =球; %#坐标数据领域
MAX_ERROR = 121; %#最大预期的错误
对于i = 1:大小(数据,1)
  C = 0.5 *数据(i,4)/ MAX_ERROR;为球体%#比例系数
  X = X * C +数据(i,1); %#新的X坐标球
  Y = Y * C +数据(i,2); %#新的Y的球坐标
  。Z = Z * C +数据(i,3); %#新的z坐标球
  的面(X,Y,Z,'EdgeColor','无'); %#地块球
  坚持住
结束
网格
轴线等
视图(-27,16);
xlabel('×');
ylabel('Y');
zlabel('T');
 

下面是它看起来是这样的:

的问题:虽然剧情看起来挺有趣,它不是很直观。此外,绘制大量的点以这种方式将得到杂乱,这将是很难看到他们都好。

更直观的三维图:

这可能是更好的,而不是使数​​据的3-D的情节,因为它可能会更容易跨preT。这里,x轴重新presents迭代次数和Y轴重新presents每个单独的网络

  plot3(1:2,[1],[2 45 6 54]); %#地块数据网络4-5
坚持住
plot3(1:3,[2 2 2],[2 32 9 98; 1 121]); %#地块数据网络7-8
xlabel('迭代次数');
集(GCA,YTick,[1〜2],YTickLabel',{'网络4-5,7-8网络'})
网格
传说('时间','错误')
视图(-18,30)
 

这会产生一个更清晰的曲线图:

I have three parameters x,y and t. But the problem is my file structure.

My files are named as:

e_x_y.txt
t_x_y.txt

where e_x_y.txt has the error for particular values of x and y and t_x_y.txt has corresponding time values.

I need to plot the values in e_x_y.txt on a x vs y vs t graph.

What is the best way to do that?

I know what x and y values are, so I don't have to deduct them from the file names.


To make things more clear,

suppose my files are:

e_4_5.txt
45
54
t_4_5.txt
2.0
6.0

e_7_8.txt
32
98
121
t_7_8.txt
2
9
1.0

I want to plot the following points:

(4,5,2.0) = 45
(4,5,6.0) = 54
(7,8,2.0) = 32 
(7,8,9.0) = 98
(7,8,1.0) = 121

解决方案

The type of plot you are trying to make may be difficult to visualize well. I can give you two suggestions: one is what you want, and one is what you should probably do instead...

Plotting 4-D data:

In order to do this, you will have to plot a series of x,y,t points and somehow represent the error value e at each point. You could do this by changing the color or size of the point. In this example, I'll plot a sphere at each point with a diameter that varies based on the error (a diameter of 1 equates to the maximum expected error). The color represents the time. I'll be using the sample data you added to the question (formatted as a 5-by-4 matrix with the columns containing the x, y, t, and e data):

data = [4 5 2 45; 4 5 6 54; 7 8 2 32; 7 8 9 98; 7 8 1 121];
[x,y,z] = sphere;  %# Coordinate data for sphere
MAX_ERROR = 121;   %# Maximum expected error
for i = 1:size(data,1)
  c = 0.5*data(i,4)/MAX_ERROR;  %# Scale factor for sphere
  X = x.*c+data(i,1);           %# New X coordinates for sphere
  Y = y.*c+data(i,2);           %# New Y coordinates for sphere
  Z = z.*c+data(i,3);           %# New Z coordinates for sphere
  surface(X,Y,Z,'EdgeColor','none');  %# Plot sphere
  hold on
end
grid on
axis equal
view(-27,16);
xlabel('x');
ylabel('y');
zlabel('t');

And here's what it would look like:

The problem: Although the plot looks kind of interesting, it's not very intuitive. Also, plotting lots of points in this way will get cluttered and it will be hard to see them all well.

More intuitive 3-D plot:

It may be better to instead make a 3-D plot of the data, since it may be easier to interpret. Here, the x-axis represents the iteration number and the y-axis represents each individual network:

plot3(1:2,[1 1],[2 45; 6 54]);           %# Plot data for network 4-5
hold on
plot3(1:3,[2 2 2],[2 32; 9 98; 1 121]);  %# Plot data for network 7-8
xlabel('iteration number');
set(gca,'YTick',[1 2],'YTickLabel',{'network 4-5','network 7-8'})
grid on
legend('time','error')
view(-18,30)

This produces a much clearer plot:

这篇关于如何绘制3D图在MATLAB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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