matlab - 如何在 Matlab 中从标量数据生成这个特定的 3D 图形?

标签 matlab matlab-figure

我正在尝试使用 Matlab 生成此图。内置的椭球函数令人困惑。对于这个问题,我有两个变量(宽度和长度)和一个恒定的高度。

为了使它变得非常简单,我想表明当我们接近尖端时宽度正在变化,但高度是恒定的。 w,x,h 是图中显示的变量。

如果有人能提供帮助,我将非常感激。

3D plot

最佳答案

我认为下面的代码会让你受益匪浅。查看示例输出: enter image description here

我添加了足够多的评论,您应该能够从这里获取它......

% plot ellipsoid in 3D

% height and width of ellipsoid:
e_h = 10;
e_w = 3;

% position where the "quivers" (arrows) go:
q_offset = 2;    % distance from axis
q_scale = 0.5;   % multiplier to give parabola some size
q_spacing = 0.5; % distance between arrows
q_height = 2.5;  % height above XY plane where arrows are drawn
N = 1000;        % number of points for drawing

theta = linspace(0, 2*pi, N); % parameter to help drawing ellipse
zerov = zeros(1, N);          % array of zeros that I will need

% coordinates of main ellipse:
x = e_w * sin(theta);
y = zeros(size(x));
z = e_h * cos(theta);

% plot main ellipse:
figure;
plot3(x, y, z)

% secondary plot
y2 = q_scale*(e_w.^2 - x.^2) + 2; % offset parabola - what your plot looked like...
hold on
plot3(x, y2, zerov+q_height);     % plotting the parabola in the XY plane at height
axis equal % make the plot dimensions isotropic

% add quivers
q_base = -e_w:q_spacing:e_w; % x coordinate; y and z are fixed
q_length = (e_w.^2 - q_base.^2)*q_scale; % length of quiver - just an equation I chose
q0 = zeros(size(q_base)); % another vector I will need multiple times
q1 = ones(size(q_base));  % ditto

% plot the arrows: the "-1" argument means "don't scale"
quiver3(q_base, q0+q_offset, q_height*q1, q0, q_length, q0, -1)

关于matlab - 如何在 Matlab 中从标量数据生成这个特定的 3D 图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14841860/

相关文章:

matlab - 简单的递归关系

matlab - 在 Matlab 中连接二元运算符(如 "3++ 2")不会出错

matlab - 在直方图/条形图中绘制两个分类数组?

Matlab - "seal"一个图形,这样绘图就不会覆盖它,但会自动创建一个新图形

c++ - 对于计算密集型函数,类函数参数是否比 C++ 中的类变量更好?

matlab - MATLAB 中的条件 "Or"语句

matlab - 在不删除颜色条的情况下在现有轴内显示新图像

matlab - 在Matlab中选择图像上的像素时,索引指的是什么?

matlab - SVM - 训练样本数与特征数之间的关系

matlab - 通过颜色渐变修补圆圈