MATLAB: Colouring dots in scatter3 according z-value

scatter3

plot3 gives colours according to height above the xy-plane. Is that possible with scatter3 too?

Best Answer

It is relatively straightforward to do what you want:
x = rand(10, 1); % Create Data


y = rand(10, 1); % Create Data
z = rand(10, 1); % Create Data
zscaled = z*10; % May Be Necessary To Scale The Colour Vector
cn = ceil(max(zscaled)); % Number Of Colors (Scale AsAppropriate)
cm = colormap(jet(cn)); % Define Colormap
figure(2)
scatter3(x, y, z, [], cm(ceil(zscaled),:), 'filled')
grid on