How to plot discrete points as colormap?

84 views (last 30 days)
Emerson De Souza on 9 Nov 2011
INTRO:
I want to plot z as color dots of each x,y-coordinate-pair. Assume the array is given as in the example below:
xvector = 5:5:100;
yvector = 5:5:75;
numX = numel(xvector);
numY = numel(yvector);
yvector = repmat(yvector(:),numX,1);
xvector = repmat(xvector ,numY,1);
COORDINATES= [xvector(:) yvector];
VALUE=(1:1:numX*numY)';
T=[COORDINATES VALUE];
[ux, ~, bx] = unique(T(:,1));
[uy, ~, by] = unique(T(:,2));
[X, Y] = ndgrid(ux, uy);
%Z = accumarray( [bx(:),by(:)], T(:,3) );
Z = accumarray( [bx(:),by(:)], T(:,3), [],[], NaN );
%h=pcolor(X,Y,Z);
%h=surf(X,Y,Z);
h=surf(X,Y,zeros(size(X)),Z);
Colorbar;
axis([90 105 50 80]);
set(gca);
set(gca,'XTick',90:1:105);
set(gca,'YTick',50:1:80);
set(gca,'XMinorTick','on');
set(gca,'YMinorTick','on');
PROBLEM: It plots a color box everywhere but I want to display only the discrete values, the vacancies should be white or any known color.
I tried different plot commands above (%) but nothing changed the situation. Hope someone knows how to do it correctly. Thanks in advance for your help
Emerson

Patrick Kalita on 9 Nov 2011
I think you want to use scatter instead of surf. Take a look at the first example in the documentation page. It closely matches what you are trying to do.

Community Treasure Hunt

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

Start Hunting!

Translated by