Not interpolating contourf function

Viewed 37

I want to represent a two variable function on Matlab that takes values {-1,1} and I am using the prebuilt function contourf since it's the only one I know to represent filled 2D plots. It is a simple function (sort of a checkerboard ina cartesian mesh) and I want the color of each cell to be determined by the value of the function on the bottom left vertex. The problem is that, for each square cell, this function it is always interpolating the value on each vertex. Is there an straightforward way to fix this?

I leave my code here as an example.

n = 3; % mesh size
L = 2^n;
x = linspace(0,1,2^n+1);
f = ones(L+1);
for j=1:L/2
    f(:,j) = -1; 
end
% this generates a basic checkerboard consisting of two stripes: one black and one white
[X,Y] = meshgrid(x);
contourf(X,Y,f,'linecolor','none');
set(gca,'Yticklabel',[]) 
set(gca,'Xticklabel',[])
set(gca,'XColor','none','YColor','none','TickDir','out')

black = [0 0 0];
white = [1 1 1];
colormap(gca,[black; white]) % binary colormap

Thank you!

0 Answers
Related