在 matlab 中绘制 3d 速度场 [英] 3d velocity field plotting in matlab
问题描述
我需要在 3d 中绘制一个球体上的彩色速度场.我正在寻找与此类似的函数:
I need to plot a colored velocity field over a sphere in 3d. I'm looking for a function that looks similar to this:
f(X, Y, Z, V)
其中 X
, Y
, Z
代表 3d坐标(使用 meshgrid
形成的 3 维矩阵)和 V
是一个 3 维矩阵,用于确定每个坐标的速度值.结果应该是一个 3d 彩色图,根据 V
中每个坐标的值改变颜色.
f(X, Y, Z, V)
Where X
, Y
, Z
represent the 3d coordinates (3 dimensional matrices that are formed using meshgrid
) and V
is a 3 dimensional matrix that determines the velocity value for each coordinate. The result should be a 3d colored plot with a changing color according to the value in V
for every coordinate.
我尝试使用 isosurface
但效果不佳,因为我需要轮廓,我只需要每个坐标中的特定值.我使用了 quiver3
并且效果很好,但我需要用颜色而不是箭头来映射绘图.
I tried to use isosurface
but it didn't work well because I need contours, I just need the specific value I have in every coordinate. I used quiver3
and it works well but I need the plot to be mapped by colors rather than arrows.
我非常感谢任何想法和解决方案,因为我一直在阅读许多类似问题的大量评论(例如:如何在 MATLAB 中绘制 4D 轮廓线 (XYZ-V)?) 并且找不到任何解决方案.
I would really appreciate any ideas and solutions as I've been reading lots comments of many similar questions (like this one: How to plot 4D contour lines (XYZ-V) in MATLAB?) and couldn't find any solution.
提前致谢.
推荐答案
我同意 Chris 的回答.但是,提供一个关于如何scatter3使用代码>
:
I agree with Chris's answer. However, it might be worthwhile to provide a little example on how scatter3
is used:
第一:
x = rand(1,100); % x-coordinates
y = rand(1,100); % y-coordinates
z = rand(1,100); % z-coordinates
i = rand(1,100)*200;
% specify the indexed color for each point
icolor = ceil((i/max(i))*256);
figure;
scatter3(x,y,z,i,icolor,'filled');
% if you omit the 'filled' option, you'll just get circles
第一个示例将根据变量 i
为您提供颜色和大小.如果您希望散点的颜色取决于 i
的值但大小一致,请考虑第二种方法:
This first example will give you colors and size based on the variable i
. If you want your scatter-points to be in a color dependent on the value of i
but of uniform size, consider this second approach:
x = rand(1,100); % x-coordinates
y = rand(1,100); % y-coordinates
z = rand(1,100); % z-coordinates
i = rand(1,100)*200;
% specify the indexed color for each point
icolor = ceil((i/max(i))*256);
% after setting the color based on i, reset i to be uniform
i = ones(size(i)).*100;
figure;
scatter3(x,y,z,i,icolor,'filled');
在定义颜色后重置i
,所有散点的大小相等.
Having reset i
after defining the colors, all scatter-points are of equal size.
这篇关于在 matlab 中绘制 3d 速度场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!