I currently have a 2-D contour plot in Matlab from an existing data set. I made an [x,y] mesh grid and used this mesh grid and z-data to produce a 2-d contour plot using contourf(x, y, z). My goal is to reproduce this same data as a colormap, with smooth color gradients, rather than as a 2-d contour plot, with distinct color bands.
I have tried using imagesc(x, y, z) with [x,y] as a mesh grid and without. I ended up with an error function "Attempt to execute SCRIPT imagesc as a function:"
x = 0.1:0.1:1
y = 0.1:0.1:1
[X, Y] = meshgrid( x , y )
Z = #data#
contourf( X , Y , Z )
title
xlabel
ylabel
I'm not quite sure what's going wrong with your attempt to use imagesc
... When I used your x
and y
and defined Z=sin(X*20)+sin(Y*20);
and ran imagesc(x,y,Z)
I got
Looking at the error message you're getting I suspect that you have a script somewhere saved as imagesc
which is somehow overwriting the imagesc
function. Try running edit imagesc
and see what comes up, is it a function?
Now as far as making this smooth looking you have two options. Firstly you could just use a higher density of points as opposed to a 10x10 grid. For example
x = linspace(0,1,1000);
y = linspace(0,1,1000);
[X, Y] = meshgrid( x , y );
Z=sin(X*20)+sin(Y*20);
imagesc(x,y,Z)
gives
Alternatively, if you want/need to stick with the low density of points you can use pcolor(X,Y,Z)
and then set shading interp
which gives