CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB Graphics
Basic 2-D Graphs Try out the following (if copy from this slide, retype single quotes in MatLab) y=[1,3,1,3,2,4]; plot(y) plot(rand(1,20)) x=0:pi/40:4*pi; plot(x, sin(x)) plot([0 4], [1 3]) gtext(‘notes’) %place cursor on the graph to insert notes grid title(‘x square’) xlabel(‘horizontal’) ylabel(‘vertical’) help plot %documentation about plot()
Basic 2-D Graphs There are different ways of drawing multiple plots on the same set of axes. Axes may be scaled as new graphs are added. Method one hold … hold Method two plot(x1, y1, x2, y2, x3, y3, …) %each pair will be a different color plotyy() gives you two y labels, on left and right
Basic 2-D Graphs Method three plot(x,y) where x and y are both matrices, or one is a vector and one is a matrix
Basic 2-D Graphs Line styles, markers and color plot(x,y, '--') plot(x,y, ‘o') plot(x,y, 'o--') plot(x,y, 'om--') You can also format these properties in the figure window.
Basic 2-D Graphs subplot Divide the figure window into several sections with each section having a different plot E.g. subplot(2,3,1) %divide the figure into 2 rows and 3 columns and place the current plot into the first section subplot(1,1,1) to go back
Basic 2-D Graphs figure(h) where h is an integer creates a new figure window or makes figure h the current figure. Subsequent plots are drawn in the current figure. E.g. figure(2) clf clears the current figure window. cla deletes all the plots and text from the current axes, leaves only the x- and y-axes and their associated information.
Basic 2-D Graphs Other type of graphs https://www.youtube.com/watch?v=XoF1PECzfMU
Basic 2-D Graphs Other type of graphs
3-D PLOTS Draw 3-D plots either in lines or as various types of surfaces. plot3(x, y, z) plot3(rand(1,10), rand(1,10), rand(1,10))
3-D PLOTS Mesh Surfaces E.g. z = x^2 – y^2 Step 1, set up the grid in the x-y plane over which the surface is to be plotted. meshgrid function can be used: [x,y] = meshgrid(0:5); Result: columns of matrix x hold the x co-ordinates of the points in the grid, while the rows of y hold the y co-ordinates. Note: the finer the grids, the finer the mesh surface. E.g. [x,y] = meshgrid(0:0.2:5);
3-D PLOTS Mesh Surfaces E.g. z = x^2 – y^2 Step 2, generate surface points z Step3, plot the surface mesh(z) or mesh(x,y,z) surf(z) or surf(x,y,z)
3-D PLOTS Mesh Surfaces E.g. Mexican Hat Note: the finer the grids, the finer the mesh surface. E.g. [x,y] = meshgrid(-8:0.1:8);
3-D PLOTS Contour Plots E.g. Initial heat distribution over a steel plate
Image Processing https://www.mathworks.com/videos/image-processing-made-easy-81718.html Image enhancement – removing noise and sharpening an image Image segmentation – isolating objects of interest and gathering statistics Image registration – aligning multiple images from different camera sources
Image Processing Additional videos – Image processing tool box https://www.mathworks.com/videos/introduction-to-matlab-with-image-processing-toolbox-90409.html Rapid development of image processing algorithms https://www.mathworks.com/videos/rapid-development-of-image-processing-algorithms-with-matlab-92910.html Medical image processing with Matlab https://www.mathworks.com/videos/medical-image-processing-with-matlab-81890.html Matlab for life scientists https://www.mathworks.com/videos/introduction-to-data-analysis-in-matlab-for-life-scientists-81712.html