1

I have function which plots some 3D figure with

scatter3(mx,my,mz,3,mx.^2+my.^2); % mx, my and mz are vectors

I see that C is a vector the same length as X and Y, so color of each point should be linearly mapped to the colors in the current colormap, per documentation.

I tried this:

cmap = colormap;
disp(cmap(mx.^2+my.^2));

but I am getting

Subscript indices must either be real positive integers or logicals.

Is there any easier way to solve this quest?

Thanks

Nemanja Boric
  • 21,627
  • 6
  • 67
  • 91
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 16:08

1 Answers1

2

That's rather easy. Colormap does not return a vector, but a matrix. This is because each colour has three components (red, green and blue).

>> size(colormap)

ans =

    64     3

>> test = colormap;
>> test(7, :)

ans =

     0         0    0.9375

EDIT ... And, I forgot something: The indices need to be integers, in one way or another. You may like to round them or turn them into an integer.

EDIT2 ... According to your example, the disp-statement works like this:

disp( cmap(1:( (size(cmap, 1)-1) / (length(mz)-1) ):size(cmap, 1), :) );
s-m-e
  • 3,433
  • 2
  • 34
  • 71