% SurfacePlotExample %----------------------------------------------------------- % An example on how to plot using the surf function. % %----------------------------------------------------------- % Johan Clausen % Department of Civil Engineering % Aalborg University % December 2014 %----------------------------------------------------------- clear all %----- Input variables ------------------------------ height = 3 ; % Domain height width = 7 ; % Domain width nx = 20 ; % Number of points in the x-direction ny = 15 ; % Number of points in the x-direction xmin = -3 ; xmax = xmin + width ; % x limits ymin = -1 ; ymax = ymin + height ; % y limits %---------------------------------------------------- %----- Calculations ---------------------- X = linspace(xmin,xmax,nx) ; % Row vector of x coordinates Y = linspace(ymin,ymax,ny) ; % Row vector of y coordinates [Xgrid,Ygrid] = meshgrid(X,Y) ; % Forms matrices of x and y coordinates. % Try writing them out in the command window. F = Xgrid.^2 - Xgrid.*Ygrid + Ygrid.^2 ; % Calculation of a function %----------------------------------------- %----- Plotting ---------------------------------------------------- figure(1) ; clf ; hold on ; surf(X,Y,F) ; xlabel('{\it x} [m]','fontname','times','fontsize',12) ; ylabel('{\it y} [m]','fontname','times','fontsize',12) ; title('Surf plot example','fontname','times','fontsize',12) ; shading interp % Makes the interpolation colors smooth. Try commenting the line out and see the difference colorbar % To hide the colorbar, simply comment out this line. axis equal % Ensures the same scale of the horizontal and the vertical axes. Try commenting this line to see the difference % if you do not want the coordinate axes displayed, uncomment the line below. Sometimes this is more pretty. % axis off %------------------------------------------------------------------- %----- The end ------------------------------------------------------