How can I plot single points, each having a different color, of two arrays(as x, and y) using a for loop?

I am pretty new to matlab. I have two 12x1 arrays. I want to use one as x and one as y. I need to create a scatter plot. However, I want to make each point a unique (possibly random if easier) color. I am unsure on how to go about this. I tried reading into it and it seems I need to create a for loop, however I dont know what to put in the for loop to make this happen.

Risposte (1)

See the documentation on scatter to see all its optional arguments and features.
x = rand(12,1);
y = rand(12,1);
figure
scatter(x, y, [], rand(12,1), 'filled')
grid
colormap(jet(numel(x)))
colorbar
.

Categorie

Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange

Prodotti

Release

R2018b

Richiesto:

il 11 Set 2021

Risposto:

il 11 Set 2021

Community Treasure Hunt

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

Start Hunting!

Translated by