Adjust the dots (x, y) and use the third (z) as the color code in Matlab

Possible duplicate:
matlab: scatter plots with lots of data points

I have 3 vectors of 315,000 elements each. X, Y and Z. X and Y are the coordinates, and Z is the value. I have to build the coordinates as points in a two-dimensional graph, Z is the color indicator for each X and Y coordinate. I tried the scatter command, but it is very slow. Anyone suggest a better way?

thanks!

+4
source share
3 answers

Depending on which color card you are looking for, you might 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 find is a bit expensive, but it seems to be faster than a scatter . I am sure you could optimize this further.

+1
source

Try cline from MATLAB file sharing here . It looks like he is doing exactly what you want.

0
source

Your code is slow due to the large size of the vectors, and not because of the SCATTER function. Try to break them into smaller vectors (for example, 10 elements each) and place each vector in a cell array cell. Then go through an array of cells and scatter each smaller vector separately so as not to load too much into memory.

 hold on for i=1:numel(XcoordCellArray): scatter(XcoordCellArray{i},YcoordCellArray{i},S,ZcoordCellArray{i}) end 
0
source

All Articles