MATLAB: Is there an example for appending data to an exisiting PCOLOR plot in MATLAB

addappendMATLABpcolorplot

I would like an example program which appends new data to an existing PCOLOR plot.

Best Answer

The following example uses the PCOLOR example in the MATLAB documentation that can be obtained by executing the following at the MATLAB Prompt:
doc pcolor
The following commands set up a simple color window, the same as in the documentation.
n = 6;
r = (0:n)'/n;
theta = pi*(-n:n)/n;
X = r*cos(theta);
Y = r*sin(theta);
C = r*cos(2*theta);
The first addition is that instead of plotting the whole wheel, only the first two segements are generated. The handle to the plot object, P, is recorded:
P = pcolor(X(:,1:2),Y(:,1:2),C(:,1:2))
The following commands grow the color wheel within a FOR loop, which has a call to PAUSE for dramatic effect. The previous values of X,Y,Z and C(color) data are obtained using the GET command. The four SET commands replace the data of the current figure with the latest ones. There is no need to otherwise regenerate the plot.
:
axis([-1 1 -1 1])
for i=3:length(X)
pause(.75);
x = get(P,'XData');
y = get(P,'YData');
c = get(P,'CData');
z = get(P,'ZData');
x = [x X(:,i)];
y = [y Y(:,i)];
c = [c C(:,i)];
z = [z z(:,1)];
set(P,'XData',x);
set(P,'YData',y);
set(P,'CData',c);
set(P,'ZData',z);
end