3d velocity field plotting in matlab

2019-06-04 01:13发布

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) 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.

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.

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.

Thanks you in advance.

标签: matlab 3d
2条回答
一夜七次
2楼-- · 2019-06-04 01:42

I would suggest using the scatter3 function. It is very customizable, and may be exactly what you are looking for.

http://www.mathworks.com/help/matlab/ref/scatter3.html

查看更多
你好瞎i
3楼-- · 2019-06-04 01:42

I agree with Chris's answer. However, it might be worthwhile to provide a little example on how scatter3 is used:

First:

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

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');

Having reset i after defining the colors, all scatter-points are of equal size.

查看更多
登录 后发表回答