MATLAB: Contour with discrete (x,y) and continuous z

contourfplot

I have a 3D data in which the x and y are piece-wise constant and z is constant in the interval of x and y. I would like to plot them with Matlab contourf function. The problem is that for an interval x,y the value z is interpolated. For example for x between x1 and x2 and y between y1 and y2, the value of z is k. Currently contourf in Matlab plots the interpolation of z around the region of x1,x2 and y1,y2. How can I keep the values of z is set constant in region between x1 and x2 and y1 and y2?
Thank you in advance.
Zul

Best Answer

That is 2D data. You have a matrix that has a value for two independent dimensions, x and y. That is 2D data. It can be represented as a image. You can increase the resolution with imresize (to get "in between" values of x and y) and the 'nearest' option if you want it to have a blocky stair step appearance. Then you can display it with imshow(), or with surf if you want a surface kind of appearance. I (and some others) call something like surf a 2.5D representation since it's not really 3D data (like a CT or MRI image where you have 3 dimensions or indexes into an array) but rather a 3D representation of 2D data.