MATLAB: How to add noise to the patch object

MATLAB

I would like to add noise to my patch object.

Best Answer

Following is an example of how uniformly distributed random noise can be plotted over a patch object.
%Create patch object
x = [0 0;0 1;1 1];
y = [1 1;2 2;2 1];
z = [1 1;1 1;1 1];
tcolor(1,1,1:3) = [1 1 1];
tcolor(1,2,1:3) = [.7 .7 .7];
h1 = patch(x,y,z,tcolor);
set(h1,'FaceAlpha',0.3); % set the transparency value to .3 (mostly translucent)
hold on
% Plot noise
n = 50;
x = rand(n,1);
y = rand(n,1)+1;
h2 = plot(x,y,'.');
set(h2,'MarkerSize',18);
hold off