# MATLAB Commands

MATLAB Commands

MATLAB (stands for matrix laboratory) is a high-level programming environment for scientific calculation, and it provides functions more efficiently than other programming languages. In addition, it has many in-build modules and integration with Simulink, which helps in complex computation.

MATLAB commands are very helpful to users to establish connection with the application. Using a command-line interface, the user can interact with the software using MATLAB's various commands.

The primary purpose of MATLAB commands is to work with the system like import/export data, loading files to carry out the application functions.

It provides various commands to serve different purposes; for example, to clear the screen, we use the command ">>clear."

### Let us look into some basic MATLAB commands

COMMANDS | PURPOSE |

clear | It clears variables from the memory |

what | MATLAB files are listed in the current directory |

pwd | Current directory is displayed |

date | Current date is displayed |

help | Just type this command at command window if you want any kind of guide or help |

who | This command helps to list the current variable |

type | Content of a file is displayed |

exist | Existence of a variable is checked with the help of this command |

clc | Command window gets cleared |

global | A variable is declared as global by using this command |

disp | Content of array or string is displayed |

fscanf | Formatted data from a file is read. |

input | To prompt for input |

format | Screen-display format |

fprintf | Writes formatted files to screen or file |

; | Screen printing |

quit | Exits from MATLAB |

lookfor | To help entries for keyword |

Let us execute some of the above-mentioned commands.

Commands like ‘whos’, ‘date’, ‘what’ are executed.

Commands like ‘pwd’, ‘help’, ‘disp’, ‘who’ are executed.

#### Now let us look into some intermediate and advance MATALB commands

Commands related to files and directory information

dir | Contents of current directory are listed out. |

rmdir | To remove a directory |

mkdir | To create new directory |

cd | To change directory |

copyfile | To copy a file |

editpath | Search path changes |

Is | Current file contents are listed |

path | MATLAB search path (sets or gets) |

delete | To Delete file |

diary | To save the text generated in MATLAB session |

! | Thiscommand provide access to Operating system. |

wklread | This command read .wk1 spreadsheet file. |

### Commands related to ON-LINE help

Any kind of help regarding the user manual or procedure to check out any features of the software can be fetched with the help of these on-line commands.

help | To provide basic help info |

helpdesk | Browser based help is provided |

demo | To run demo program |

doc | Web HTML documentation |

info | MATLAB information is displayed |

whatsnew | ReadMe files are displayed |

echo | Script file echo command |

home | To send cursor home |

Let us execute some of the above-mentioned commands.

Commands like ‘helpdesk’, ‘demo’, ‘doc’ are executed.

### Commands for general use

General use in the sense to fetch basic information of our computer like date and time or type of computer we use. Let us look few of them mentioned below.

computer | Returns which type of computer your using |

clock | Vector format of clock time and data |

more | Paged output is controlled |

ver | License and version of MATLAB data is displayed |

bench | To provides benchmarks |

^c(Control-c) | To locally abort |

startup | To execute M-file |

tic | To start stopwatch |

toc | To read the time of stopwatch |

etime | To find elapsed time function |

cputime | To find elapsed CPU time |

matlabarc | Master start-up file |

**Let us execute some of the above-mentioned commands.**

Commands like ‘computer’, ‘clock’, ‘ver’, ‘bench’, ‘tic’, ‘tac’, ‘cputime’ are executed.

Commands ‘ver’ and ‘bench’ are executed.

Commands ‘tic’, ‘tac’, ‘cputime’ are executed.

### Commands on mathematical computations

Here are few MATLAB commands which are especially programmed for carrying out various mathematical computations like array manipulation, solving linear algebra, integration, polynomial, calculus, elementary math, etc.

Commands for Matrix arithmetic | |

eye | An identity matrix is created |

ones | Array of ones is created |

zeros | Array of zeros is created |

dot | To generate Dot product of two matrices |

cross | To generate cross product of two matrices |

Commands for array operations | |

cat | To concatenate two arrays |

length | To calculate no. of elements in the array |

min | Minimum value of array is returned |

max | Maximum value of array is returned |

Commands for matrix for linear equations | |

rank | Returns the rank of a matrix |

det | Determinant of the matrix is returned |

inv | To return inverse of a matrix. |

Commands for polynomial | |

poly2sym(vector) | This helps to convert vector to symbolic polynomial. |

poly2sym(vector,’v’) | This is also similar to poly2sym(vector). |

Commands for strings | |

findstr | To find start index in a given string. |

strcmp | To compare two given strings, returns 1 if match is found or else it returns 0. |

linsolve() | To solve linear expressions. |

contour() | To solve linear expressions. |

.