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.
Matlab can be used for –
- Data analysis
- Algorithm development
- 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 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 in Matlab with the help of examples
Basic Matlab Commands
1. Clear – This command removes variables from the memory
2. Exist – This command checks for the existence of a variable
3. Clc – This Matlab command clears the command window
4.5 (1,590 ratings)
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 Matlab 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
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 Matlab 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
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.
3. Matrix Related Commands
- Eye – This creates an identity matrix
- Ones – This creates the array of ones
- Zeros – This creates the array of zeros
4. Matrix Arithmetic Command
- Dot- This Matlab 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
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.
6. Timing related commands
Cputime – Calculates the CPU time in seconds
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.
Advanced Matlab Commands
Let’s take a look at some of the Advanced Matlab commands which are as given below:-
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).
2. Polynomial related commands
- Poly2sym(vector) – This Matlab 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).
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
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
This can be solved in accordance with the attached image
Tips and Tricks to Use Matlab 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
We are supposed to design a function with given syntax
function a = findArea(width,margin)
% 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 Commands
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.
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 –