The method proposed by ImageAnalyst at 5th level is the solution with Matlab. But the result image is not a continuous image, but an image composed of descrete points. Their intensity values reveals the depth values.
If your application is not restricted with Matlab, and you do want to create a continuous depth map, you can use C++ and VTK to realize it. It directly extract the depth values from GPU for each pixels on you screen, thus the depth map is smooth and looks really nice. My code was submitted to the website as a good-to-go example, and you can get it from VTK website.