- Start learning MATLAB and Simulink with free tutorials Expand your knowledge through interactive courses, explore documentation and code examples, or watch how-to videos on product capabilities. Note: You must be on a desktop computer to take courses.
- MATLAB is a high-level language and interactive computing environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C, and Fortran.
- MATLAB for Engineers, 2e is ideal for Freshman or Introductory courses in Engineering and Computer Science. With a hands-on approach and focus on problem solving, this introduction to the powerful MATLAB computing language is designed for students with only a basic college algebra background.
- Select MATLAB in the list of languages. Alternatively, saving the file with a.m extension, will allow VS Code to understand that it is a MATLAB file, and automatically select the language correctly.
Matlab Programming Examples give you a brief overview of Matlab programs. Generally, Matlab programming can be done using object-oriented programming, GUI programming, and basic Matlab syntax and functions. Students must be aware of Matlab programming in order to implement a complete project in Matlab.
After reading the MATLAB plots topic, you will understand how to create plots, and you will know how to use various plot commands in MATLAB.
Plots are useful in providing information in picture view and MATLAB provides the facility for creating a plot using plot command.
plot Command
The plot command in MATLAB help to create two-dimensional plots. The general form of the command is: Cisco anyconnect chromebook.
Line specifiers | Style (color) | Line specifiers | Style (marker) | Line specifiers | Style (line) |
---|---|---|---|---|---|
b | Blue | s | Rectangle marker | -- | Dashed line |
c | Cyan | o | Circle | : | Dotted line |
k | Black | x | x-mark | -. | Dashpot |
g | Green | + | Plus | (no line) | None |
y | Yellow | * | Star | - | Solid line |
w | White | d | Diamond | ||
m | Magenta | . | Point marker | ||
r | Red |

where
- x and y both are vectors.
- The table below shows the following line specifiers which are Optional.
Examples
Program (1): To plot the curve for x and y values are given below, in MATLAB.
x=(1,2,3,4); y=(2,4,6,8)
MATLAB VIEW – Program (1):
Create a script file in MATLAB and type the following code –
MATLAB VIEW – Output (1):
Program (2): To plot curve with a line specifiers as a dashed red line for x and y values are given below, in MATLAB.
x = (1,2,3,4); y = (2,4,6,8).
MATLAB VIEW – Program (2):
Create a script file in MATLAB and type the following code –
MATLAB VIEW – Output (2):
In the above plot x vs. y, with a dashed red line.
Multiple graphs using plot command

The example below will show you how to show multiple graphs in the same plot using plot command in MATLAB.
Examples
Program (1): To show curve in same plot for functions f(x) and g(x) is given below in MATLAB.
f(x) = x; g(x) = 2x; 0 ≤ x ≤ 10
MATLAB VIEW – Program (1):
Matlab For Loop
Create a script file in MATLAB and type the following code –
MATLAB VIEW – Output (1):
In the above figure f vs. x and g vs. x, all in the same plot.
hold on and hold off command
The example below will show you how to show multiple graphs in the same plot by using hold on and hold off command in MATLAB.
Example
Program (1): To show the curve for functions f(x) and g(x) in the same plot is given below, in MATLAB. Hand drawn art.
PDFSam is an open-source PDF editor Windows that offers one open-source PDF editors and one commercial one. PDF Basic is a tool that allows you to merge, split, extract pages, rotate, and mix PDF files. It is available for Windows, Mac, and Linux. Free and open-source since 2006. Open source pdf editor. PDF Architect Free is a open-source PDF editor for Windows developed by PDF forge. With the assistance of this tool, you can create PDF files from Excel, Word, PowerPoint, and other 300+ file formats. It is a fully functional PDF editor out there for your document needs. PDFSam basic is a PDF file editor that supports merging, splitting, and editing of PDF files. It is also an open-source PDF editor. If you would like to edit or re-arrange the order of pages in a PDF file, this program is worth a try. It is a java application and can run on any device that has Java runtime. If you already own Microsoft Word 2019, 2016, or 2013, then skip all the suggested programs below: you have a great PDF editor at your disposal right now. Just open the PDF as you would any Word document, give the program a few minutes to convert the PDF, and then edit away. This also works in Google Docs.
f(x)=x; g(x)=2x; 0≤x≤10
MATLAB VIEW – Program (1):
Create a script file in MATLAB and type the following code –
MATLAB VIEW – Output (1):
MATLAB – Plot formatting Using Commands:
The formatting commands are entered after the plot command. In MATLAB the various formatting commands are:
Matlab For Students
(1). The xlabel and ylabel commands:
The xlabel command put a label on the x-axis and ylabel command put a label on y-axis of the plot.
The general form of the command is:
Matlab While
(2). The title command:
This command is used to put the title on the plot. The general form of the command is:
(3). The axis command:
This command adds an axis to the plot. The general form of the command is:
(4). The grid command:
This command adds the grid to the plot. The general form of the command is:
Example
Program (1): To plot sine wave having following properties given below, in MATLAB.
f(x) = sin(x); 0 ≤ x ≤ 2π; Properties: Sine wave: axis and grid present, x-axis label “time”, y-axis label “amplitude”, title label” sine wave”.
MATLAB VIEW – Program (1):
Create a script file and type the following code –
MATLAB VIEW – Output (1):
