# Fast way to plot points with different colors

19 Ansichten (letzte 30 Tage)
Edward am 29 Sep. 2013
Kommentiert: Edward am 29 Sep. 2013
Hi, i have a matrix in the form
colorData=
[x1,y1,r1,g1,b1;
x2,y2,r2,g2,g2;
x3,y3,r3,g3,g3;
.............
xi,yi,ri,gi,gi];
where r,g,b are the colors for each data point.
currently I have been plotting using:
hold on
for a=1:length(colorData(:,1)) %for every row
color = [colorData(a,3),colorData(a,4),colorData(a,5)];
plot(colorData(a,1),colorData(a,2),'o','markerfacecolor',color,'markeredgecolor',color);
end
hold off
which works but takes about 3 seconds to execute for the large matrices im using. I can plot the x,y data in about 100ms so the problem is not really how much data im using.
Surely there must be a quicker, more efficient way to do this?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Image Analyst am 29 Sep. 2013
Try using scatter() instead of that loop. With scatter() you can pass in colorData so that each marker has the color you specify.
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Image Analyst am 29 Sep. 2013
How many elements are there? If there are more than a couple hundred, it might look so cluttered that it's just overkill. You may be able to throw up a subsample set of points and it will look substantially the same as if you put up all of them.
Edward am 29 Sep. 2013
Theres quite a lot, ill see if i can reduce how many points there are. I dont want to loose important data though

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Axis Labels finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by