MATLAB Plotting Study Notes with Code Examples

Resource Overview

Comprehensive MATLAB plotting study notes covering fundamental techniques with practical code implementation examples for 2D/3D visualization

Detailed Documentation

MATLAB is a powerful data visualization tool offering extensive plotting capabilities that enable users to quickly generate high-quality 2D and 3D graphics. Whether used for data analysis, algorithm validation, or academic research, plotting remains one of MATLAB's most frequently utilized features.

### Basic 2D Plotting The simplest plotting method in MATLAB utilizes the `plot` function. By passing a set of data points, MATLAB automatically generates a line graph. For example, given horizontal coordinate `x` and vertical coordinate `y`, calling `plot(x, y)` produces a continuous curve. The function supports customization of line colors (using color specifiers like 'r' for red), line styles ('--' for dashed lines), and marker symbols ('o' for circles) to enhance visual clarity.

For plotting multiple datasets, users can overlay multiple curves in the same figure window. While MATLAB automatically adjusts axis ranges by default, finer control can be achieved using `xlim` and `ylim` functions to manually set axis boundaries with syntax like `xlim([min_value, max_value])`.

### Graph Customization To improve graph readability, MATLAB provides functions for adding titles, axis labels, and legends. The `title` function adds a main title, while `xlabel` and `ylabel` annotate the horizontal and vertical axes respectively. The `legend` function distinguishes between different curves by displaying identifiers. Additionally, `grid on` activates grid lines, improving data comparison visibility through visual reference lines.

### 3D Graphics Plotting Beyond 2D graphics, MATLAB supports comprehensive 3D data visualization. The `plot3` function creates 3D line plots suitable for displaying spatial trajectories, requiring three coordinate vectors (x,y,z) as input. For surface representation, `surf` and `mesh` functions generate 3D surface and mesh plots respectively, ideal for visualizing complex function distributions across spatial dimensions. The `view` function controls perspective angles (azimuth and elevation) enabling multi-angle observation of 3D objects.

### Subplots and Multi-Figure Display For displaying multiple graphs in a single window, the `subplot` function divides the figure area into an m-by-n grid, allowing different plots in each subsection using syntax `subplot(m,n,p)` where p indicates the current plot position. This approach is particularly effective for comparing results under different parameters or datasets.

MATLAB's plotting capabilities are both powerful and flexible. After mastering these fundamental operations, users can advance to exploring advanced features including animation creation, interactive graphics, and custom style configurations to meet sophisticated visualization requirements.