EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab Commands
 

Matlab Commands

Priya Pedamkar
Article byPriya Pedamkar

Updated March 18, 2023

Matlab Commands

 

 

What is Matlab?

It is abbreviated as Matrix-based language, has been designed for computer scientists and engineers. Matlab provides great solutions in computational mathematics.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

It can be used for –

  1. Data analysis
  2. Algorithm development
  3. Create models and application

Matlab finds a great use case in machine learning and deep learning as they deal with n-dimensional space which can be represented and analyzed in the matrix form only. Apart from this other technologies using this are control system design, image processing, and computational finance.

Matlab Commands

Matlab provides the commands that are used while the user has to interact with the application using the command line interface. Here we will see how to use those commands with the help of examples

Basic Commands

1. Clear – This command removes variables from the memory

2. Exist – This command checks for the existence of a variable

3. Clc – This command clears the command window

4. Global – This command declares a variable as global

5. Help – If you need to search for any help just write the keyword at command window and it displays your available options

6. Who – This command lists the current variable

7. Type – This command displays the contents of a file.

8. Pwd – This command displays the current directory.

9. Date – This command displays the current date

10. What – This command lists all the Matlab files in the current directory

Example 1:

Matlab Commands Example 1

Example 2:

Matlab Commands Example 2

Example 3:

Matlab Commands Example 3

Example 4:

Matlab Commands Example 4

Example 5:

Matlab Commands Example 5

So if you would clearly observe the example 5 presented above, you can see that the statements hold true and in the last example we called clear command first and thereafter we looked for a type of x and y which now came to be undefined but was not so in example 4.

Note that these examples have been presented with octave that is open source and equivalent platform to Matlab and uses the same command set.

Intermediate Matlab Commands

Below are the intermediate commands which are as follows:

1. Mathematical Functions

Here we are exploring plot command which is being used to plot the sinusoidal wave curve with time, where time is ranging from 1 to 30 and is increasing in intervals of 0.01.

In a similar way, we can do this for any other trigonometric function too which constitutes the major part of mathematics

Mathematical Functions

2. Array related Commands
  • Cat– It is used to concatenate two arrays, the first argument it takes is a dimension of the array to be created like whether it is 1D,2D or n-dimensional array and thereafter that n-number of arrays are passed as arguments, those are to be concatenated as shown in the snapshot
  • Length – Computes the number of elements in the array
  • Min, max – These commands return the max and min elements present in the arrays.

Array related

3. Matrix Related Commands
  • Eye – This creates an identity matrix
  • Ones – This creates the array of ones
  • Zeros – This creates the array of zeros

Matrix Related

4. Matrix Arithmetic Command
  • Dot- This command generates the dot product of two matrices, note that the columns and rows of matrix decide the resulting matrix creation
  • Cross – Synonymously this creates the cross product, helpful in vector operations when represented in the matrix form

Matrix Arithmetic

5. Matrix Commands For linear equation related operations
  • Rank – This command provides the result to an important mathematical parameter of matrices called rank which is the quantification of the lowest order of non-zero determinant carrying sub-matrix in the parent matrix
  • Det – Determinant of the matrix is calculated using this command.
  • Inv – Execution of this command provides us the inverse of a matrix.

Matrix For linear equation related operations

6. Timing related commands

Timing related commands

Cputime – Calculates the CPU time in seconds

CPU time

7. String Related commands
  • Findstr – Finds occurrences start index of a String in a phrase.
  • Strcmp – This command is used to compare two strings, returns 1 if the match is correct else it returns 0.

String Related commands

Advanced Matlab Commands

Let’s take a look at some of the Advanced commands which are as given below:-

1. Contour

Whenever you are dealing in control system designs in engineering, the Nyquist plot contours, etc give you a mark of the stability in the system, we can customize the style of the plot in the Matlab (like the color and line type, etc).

Contour

2. Polynomial related commands
  • Poly2sym(vector) – This command converts a vector of coefficients into the corresponding symbolic polynomial (from highest to lowest power).
  • poly2sym(vector, ‘v’) – This command converts a vector of coefficients into the corresponding symbolic polynomial inv (from highest to lowest power).

Polynomial related commands

3. Commands for Equation solving

syms x1 x2…xn; solve(eq1,eq2,…,eqn, x1, x2,…,xn) – This command solves the simultaneous n number of equations and the solutions against those are assigned to variables ranging from x1,x2 to xn.

The below attached image carries the demonstration

Commands for Equation solving

4. Commands for solving the Linear System of Equations

X = linsolve (A, B) – Let us suppose that we need to find a solution against the given equation

2x+y+z+m=1

x+2y+z+m=2

x+y+2z+m=3

x+y+z+2m=4

This can be solved in accordance with the attached image

Commands for solving the Linear System of Equations

Tips and Tricks to Use commands

  • A programmer shall be aware of use cases like when does Matlab do in-place calculations.
  • Use flexible indexing when dealing with tables
  • Write Matlab functions with flexible calling Syntax

Example –

We are supposed to design a function with given syntax

function a = findArea(width,margin)
% findArea(width)
% findArea(width,height)
% findArea(... 'shape',shape)

so here, by use of inputParser, you can specify which input arguments are required (width), which are optional (height), and which are optional name-value pairs (‘shape’). inputParser also lets you confirm that each input is valid

As inputParser is a MATLAB object. Make sure to first create an object and then call functions to add the various input arguments.

Conclusion

MATLAB is a platform for scientific calculation and high-level programming which uses an interactive environment to perform complex calculations more efficiently than with traditional languages, such as C and C++.

Has supporting modules for multiple operations, has integration with Simulink which can be used for simulating the electronic control systems, do the complex computations related to numerical methods, digital signal processing, image processing, and video processing.

Recommended Articles

This has been a guide to Matlab Commands. Here we have discussed basic, intermediate as well as advanced Matlab Commands. You may also look at the following article to learn more –

  1. How to Use Docker Commands?
  2. List of Rails Commands
  3. Guide to CSS Commands
  4. Basic to Advance C# Commands
  5. MATLAB Functions | Types of Functions with Examples
  6. Guide to Simulink Matlab Function

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - ENROLL NOW