Wednesday, December 14, 2011

Difference between pcolor() and imagesc() in Matlab

A simple matrix is plotted using both pcolor() and imagesc() commands in Matlab. And the difference between them are shown in the following figure:

% Difference between pcolor and imagesc
A=[ 1  2  3  4;
    5  6  7  8;
    9 10 11 12;];
figure (1); clf; set(gcf,'Color',[1 1 1]);
subplot(1,2,1);
pcolor(A); colorbar;
title('pcolor(A)')
subplot(1,2,2);
imagesc(A); colorbar;
title('imagesc(A)')


Basically, pcolor() does not show the last column and row of the matrix. Although the original matrix is 3x4, the pcolor() plot shows 2x3 submatrix.