4

Possible Duplicate:
matlab: scatter plots with high number of datapoints

I have 3 vectors of 315,000 elements each. X,Y, and Z. X & Y are coordinates and Z is a value. I must plot the coordinates as points in a 2D graph, the Z is a color indicator at each coordinate of X and Y. I've tried the "scatter" command, but it extremely slow. Would anybody suggest a better way?

thanks!

Community
  • 1
  • 1
Oliver Amundsen
  • 1,491
  • 2
  • 21
  • 40

3 Answers3

1

Depending on what kind of color map you are looking for, you can try something like

zmin=min(Z);
zmax=max(Z);
map=colormap;
color_steps=size(map,1);

hold on
for i=1:color_steps
    ind=find(Z<zmin+i*(zmax-zmin)/color_steps & Z>=zmin+(i-1)*(zmax-zmin)/color_steps);
    plot(X(ind),Y(ind),'o','Color',map(i,:));
end

The finding is a little expensive but it seems to be quicker than scatter. I'm sure you could optimize this further.

RussH
  • 329
  • 2
  • 17
0

Try cline from MATLAB file exchange here. It looks like it does exactly what you want.

dinkelk
  • 2,676
  • 3
  • 26
  • 46
0

Your code is slow because of the large size of the vectors, not because of the SCATTER function. Try breaking them down into vectors of smaller size (say, 10 elements each) and putting each vector into a cell of a cell array. Then loop through the cell array and scatter each smaller vector individually to avoid loading too much into the memory.

hold on
for i=1:numel(XcoordCellArray):
  scatter(XcoordCellArray{i},YcoordCellArray{i},S,ZcoordCellArray{i})
end
Drosophila
  • 255
  • 1
  • 7