To get a rectangular domain that goes from x=1 to x=10 in steps of .5, and from y=1 to y=10 in steps of .5 using meshgrid, you can use
[x, y] = meshgrid([1:.5:10],[1:.5:10]);Then, you can do a 3d plot by caculating some z values on the x and y domains, and doing a surface, mesh, or contour plot.
z = x.^2 - y.^2 surf(x,y,z) mesh(x,y,z) contour(x,y,z)You could also use surfc or meshc to get surface or mesh plots with a contour plot drawn on the x-y plane. Surface plots and mesh plots color the plots according to the z value, by default. You can use some other equally-sized matrix to get the coloring instead by adding that matrix as an extra argument, like:
c = x.^2 + y.^2; mesh(x,y,z,c)
colormap('jet')If you type "help hsv", the see also list includes the other predefined colormaps.
You can get a colorbar that indicates what colors correspond to what values with
colorbarSometimes, a 3d surface plot may cover up portions of its plot. You can take advantage of the fact that Matlab doesn't plot NaN's and Inf's (remember the debugging problem?) to make "cutouts" in a plot. An example of this is in an m-file in the homework directory (/mit/2.670/Computers/Matlab/Examples), so you should be able to run it by typing "NaNdemo" at the matlab prompt , and see how the cutout was made by typing "type NaNdemo".
text(x,y,'Some Text Here')lets you place arbitrary text at some position on your graph. You give it x and y values (using the axes on your current plot), and you can put text at that location.
gtext('Some Text Here')lets you place text using the mouse button.
Another useful mouse command is "ginput". If you type
[xclick yclick] = ginputyou can click any number of points in your graph, and hit return in the graph window when you are done. It will save the x and y coordinates of the points you have clicked in the vectors xclick and yclick. This is especially useful if you have something like a plot of a decaying sine wave, and you want to know about the exponential decay of the peaks instead of worrying about the whole sinusoidal part. You can just click on each peak with the mouse in ginput, and then analyze the exponential decay of those points with a curvefit or something similar.
(This was not covered in class, but it is also interesting and useful...) Another useful set of commands, in the "graphics" toolbox, are stext, sxlabel, sylabel, stitle, etc. Read the help on stext for a basic idea of using them. You can do things like combine greek fonts, italicized fonts, different font sizes, etc into your graph, fairly easily, using latex-like formatting commands.)