简体   繁体   English

MATLAB 3D曲线图

[英]MATLAB 3D Plotting of Curves

I have 2 variables that I'm trying to graph and I can't figure out what functions to use in order to get the desired graph that I want. 我要尝试绘制2个变量,但无法弄清楚要使用哪些函数才能获得所需的图形。 For example, I have a variable Depth which is a 70x12 matrix full of numbers. 例如,我有一个变量Depth,它是一个充满数字的70x12矩阵。 12 is for each month of the year. 每年的每个月12个。 I'm trying to graph Depth against Temperature which is also a 70x12 matrix full of numbers. 我正在尝试针对温度绘制深度,这也是一个70x12的数字矩阵。 The current way I am doing this is by using plot3 in a for loop with hold on and plotting each Depth vs Temperature curve separated by 1 on the z-axis. 我目前这样做的方法是在for循环中使用plot3并保持不变,并在z轴上绘制每个以1分隔的深度与温度曲线。 That looks like this: 看起来像这样:

And when rotated it looks like this: 当旋转时,它看起来像这样:

However, what I want is some sort of meshgrid or surf inbetween my curves so that my graph would look something similar to this. 但是,我想要的是曲线之间的某种网格或冲浪,以便图形看起来与此相似。 I played around with surf and mesh a decent bit but I can't figure out how to use the data that I have stored in my variables to plot curves and a surface through the curves that looks anything like that. 我在网上冲浪并进行了不错的划分,但我不知道如何使用存储在变量中的数据来绘制曲线和通过曲面的曲面,看起来像这样。

在此处输入图片说明

You can do what you want using plot3 and surf but it is highly advisable to create matrices of both the depth and the temperature and the months using meshgrid. 您可以使用plot3surf进行plot3 ,但是强烈建议使用plot3创建深度,温度和月份的矩阵。

The following code shows how to do this. 以下代码显示了如何执行此操作。 I just made up some arbitrary temperature data called temps and then used meshgrid to turn the vector of depths and months into a grid corresponding to each entry in temps. 我只是做了一些所谓的任意温度数据temps ,然后用meshgrid把深度和个月的载体导入对应于临时工每个条目的网格。 Notice that because M and D are now matrices I don't need a for loop and can just plot3 them all at once. 请注意,由于MD现在是矩阵,所以不需要for循环,只需一次plot3所有3矩阵即可。

% create some data. The problem is that depths and months are vectors while
% I have a 70x12 grid o temperatures:
nd = 70;
depths = linspace(0, 1e3, nd);
months = 1:12;
temps = sin((1:nd)'*months/(nd*8));


% So make temps and depths matrices too:
[M, D] = meshgrid(months, depths)

% and now plot:
figure(112)
clf

% plot the surface from the matrices returned by meshgrid: notice I used
% facealpha to change the transparency:
hs = surf(temps, D, M, 'facealpha', .5);
hold all;

% now that we used meshgrid we can plot everything at once:
plot3(temps, D, M, 'linewidth', 3)

view(3)
grid on

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

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