
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Editors
Matlab comes with a built-in powerful editor that helps to write your code and also to compile , debug and see the output. When you log in to Matlab this will be the screen that is displayed to you.

To open a editor you can type edit or type edit along with filename in command window.For example
>>edit >>edit test.m
The matlab files are saved with the .m extension. Let us first just type edit in the command window and see the editor opening.

Now, let us type edit test.m in the command window and see the editor opening.

On enter you will see the dialog box asking to confirm since the file is new. The file test.m is not existing and will be created, if it exists it will be opened directly.
Click on Yes and it will open a new file test.m in the editor as shown below.

Now, let us write a small piece of code in the editor and run the same.
function [m,n] = test(x) n = length(x); m = sum(x); end
The function name:test will take the vector as input and return the sum of the vector and the length of it.
Let us enter the function inside the editor test.m, as shown below.

Save the changes and in the command line you can execute as shown below.
>> a = [10, 20, 30, 40] a = 10 20 30 40 >> [m, l] = test(a) m = 100 l = 4 >>
We are giving the vector a = [10, 20, 30, 40], to the function test. It returns m and l where m is the sum of the vectors and l is the length.
Another thing to do in the editor is you can write the instruction inside the editor as shown below −

So we have the above instruction , let me select line no 1 to 3 and execute it as shown below.

>> x = 10 y = 20 z = x*y x = 10 y = 20 z = 200 >>
Live Editor in Matlab
The live editor is yet another powerful editor wherein the user can write/edit code, debug and run it in Matlab.
It allows you to do analysis with data that supports the following −
- Display output together with your MATLAB® code.
- Use formatted text to describe your approach.
- Use equations to describe the underlying mathematics.
- Use images to illustrate important points.
- Add links to background material.
- Use controls to modify parameters and re-run the analysis.
- Plot data for visualisation.
- Invite colleagues to extend your analysis.
How to use a Live Editor?
In Matlab you will get the Live Editor tab directly when you open matlab. Or else inside the home tab you can click on New Live Script, it will open the Live Editor.

Enter your code inside the editor and use the run button to execute the code. The output will be displayed at the right side section. In the section below let us enter code and execute it.
Create Live Script
To create the live script you can click on the Home tab. Inside there select New Live Script. The files in the live script are stored with the .mlx extension.
You can also open the file in live script using the edit command. So specify the file name after edit command for e.g
edit test.mlx
If the file test.mlx already exists it will open in the live editor. If the file is a new one it will open the blank editor.
Here is the code which simply plots the random number from 25 to 1.
n = 25; r = rand(n,1); plot(r)
When you execute above the display is as follows −

In the above case when you execute you can see the output is placed at the right side.
Formatting Text in Your Live Editor
As mentioned earlier there is a lot of stuff you can do inside the live editor and one of it is formatting text.
You can formattext, add hyperlinks, images and maths formulas.
To add text you can do the following

See the highlighted block. It allows you to select title, heading etc and enter inside the editor.
You can also make use of keyboard shortcuts as shown below −
Text Style | Auto Formatting | Keyboard Shortcut |
---|---|---|
Title | # text + Enter | Ctrl + Alt + L |
Heading 1 | ## text + Enter | Ctrl + Shift + 1 |
Heading 2 | ### text + Enter | Ctrl + Shift + 2 |
Heading 3 | #### text + Enter | Ctrl + Shift + 3 |
Bullets |
* text - text + text |
Ctrl + Alt + U |
Hyperlink | URL + space or enter | Ctrl + K |
Bold |
**text** _text_ |
Ctrl + B |
Enter Equations in You Live Editor
Adding equations is very easy inside a live editor. To do that, just click on the INSERT tab in MATLAB as shown below.

Click on Equation where you want to insert the equation. The Equation shows a variety of symbols that are used to construct the Maths equations −

Once you click on the Equation the cursor in the editor will prompt you to Enter your equation.
Click on the symbols to construct your equation you want. Besides using the Equation tab, you could also make use of keyboard shortcuts.
For example you want the symbol pi, Inside Enter your equation section just type \pi and you should see the pi symbol as shown below.

Once you type \pi , the dropdown filters the symbols starting with pi. You can select the one you want and you should see the pi symbol as shown below.

If you want to see the full list available for you to select from keyboard shortcuts just type \ and the dropdown will give you the full list.
For Example

You can make use of symbols like _, ^ and / to achieve below results.
- x_2 will give you x2 in the equation you want.
- x^2 will give you the result x2
- x/2 will give you the result x/2
Let us see the example in the Live Editor
