Hello!
Quick question: I have a 3-by-n matrix with three rows, x- and y-coordinates of 5-15 randomized points on the first two rows, and mass on the 3rd row, ranging from 10-1000kg. I want the color of these points to be based on the mass, for instanse big mass=red, low mass=blue. I use the scatter function to plot these points and tried to use the third row of my matrix for color, but the colors seemed to be random. Is there a simple way of doing this?
Thanks!

 Respuesta aceptada

Star Strider
Star Strider el 19 de Oct. de 2018
This seems to color them correctly:
M = [randperm(20)', randperm(20)', randi(1000, 20,1)];
figure
scatter(M(:,1), M(:,2), 50, M(:,3), 'Filled')
colormap(jet(size(M,1)))
grid on
Also, it depends on the colormap (link) you are using. The jet (link) function (that I use here) colors them about the way you want.

2 comentarios

Viktor Bodin
Viktor Bodin el 19 de Oct. de 2018
Yep this seems to work! Thank you :)
Star Strider
Star Strider el 19 de Oct. de 2018
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Oct. de 2018

Comentada:

el 19 de Oct. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by