%% 2D plots x=(0:0.1:1); xx=(0:0.01:1); f=x.^2; g=xx.^3; figure(1) clf % clear plot plot(x,f, 'b:o', xx,g) set(gca,'FontSize',18) grid on xlabel('x') ylim([0 0.8]) %% 3D plots y=(-1:0.1:1); [x3,y3]=meshgrid(x,y); h=sin(x3*pi).*sin(y3*pi); figure(2) clf surf(x3,y3,h, 'LineStyle', 'none') set(gca,'FontSize',18) view(2) %specify viewpoint colorbar % add colorbar %% plotting part of a 3D plot figure(3) clf subplot(1,2,1) %use subplot to plot in two separate panels iy=3; %choose the element of y=array plot(x,h(iy,:)) set(gca,'FontSize',18) legend(['y=',num2str(y(iy))]) subplot(1,2,2) %second panel y0=0.71; h0=interp2(x3,y3,h,xx,y0+0*xx,'cubic'); %or interpolate the data plot(xx,h0) set(gca,'FontSize',18) legend(['y=',num2str(y0)])