1

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.

Community
  • 1
  • 1

2 Answers2

1

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

hoogamaphone
  • 1,092
  • 10
  • 20
1

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.

Schorsch
  • 7,761
  • 6
  • 39
  • 65
  • Thank you both very much for your time and effort. This solution works though I use 'trisurf' with 'convhull' command instead after some experimenting. – Avshalom.Offner May 24 '13 at 13:43
  • With a given data matrix V it looks like this: phi = -pi/2:a:pi/2; theta = 0:b:2*pi; r = r1:c:r2; [PHI, THETA, R] = meshgrid(phi, theta, r); [x, y, z] = sph2cart(THETA, PHI, R); x = x(:); y = y(:); z = z(:); M = convhull(x, y, z); trisurf(M, x, y, z, V, 'facecolor', 'interp', 'EdgeColor', 'none'); – Avshalom.Offner May 24 '13 at 13:49
  • 1
    @Avshalom.Offner : You can answer your own question if you want to give that comment more room. – Schorsch May 29 '13 at 18:01