MATLAB Commands Last Updated : 04 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report MATLAB is an interactive multi-programming language and numeric computing environment developed by MathWorks. MATLAB provides the Commands that will be used when the user wants to interact with any application using the command line interface. Following are the lists of commands used in MATLAB. Commands for Managing a SessionCommand Use clcClears command windowclearRemoves the variables from memoryglobalDeclares variables globallyexistChecks for the existence of a particular file or memoryhelpSearches for a help topicquitStops MATLABwhoLists current variables in uselookforSearches help entries for a keyboard Example 1 Matlab % MATLAB Code to illustrate % global function setGlobalx(val) global x Output: x = val; Example 2 Matlab % MATLAB Code to illustrate who x = 2 who Output: Variables in the current scope: x Example 3 Matlab % MATLAB Code to illustrate % clear clear type x Output: error: type 'x' is undefinedCommands for Working with the SystemCommand UsecdChanges current directorydate Displays current datedeleteDeletes a filedirLists all the files in a directorypathDisplays search pathpwdDisplays current directorytypeDisplays content of a filewklreadReads.wk1 spreadsheet filesaveSaves workplace variables in a file Example 1 Matlab % MATLAB Code to illustrate % pwd pwd Output: ans = /home/oo Example 2 Matlab % MATLAB Code to illustrate % date c = date Output: c= '18-jun-2021'Input and Output CommandsCommand UsedispDisplays content of an array or a stringfscanfReads formatted data from a fileformatControls screen-display formatfprintfPerforms formatted writes to file or screen inputDisplays the prompt and waits for input;Suppresses screen printing Example 1 Matlab % MATLAB Code to illustrate % disp A = [15 150]; S = 'Hello World.'; disp(A) disp(S) Output: 15 150 Hello World. Example 2 Matlab % MATLAB Code to illustrate %input age = input('how old are you: '); % At this point, the variable: age, will contain % whatever value the user types Output: 20 Vector, Matrix, and Array CommandsCommand Usecat Concatenates the arrayfindFinds the indices of nonzero elementsmax Returns the largest elementminReturns the smallest elementprodProduct of each columnsortSorts each columnrankComputes rank of a matrixeyeCreates an identity matrixinv Computes the inverse of a matrix Example 1 Matlab % MATLAB Code to illustrate %cat array1 = [1,2,3] array2 = [4,5,6] cat(1,array1,array2) Output: ans = 1 2 3 4 5 6 Example 2 Matlab % MATLAB Code to illustrate %max max(array1) Output: ans = 3 Example 3 Matlab %MATLAB Code to illustrate %min min(array2) Output: ans = 4 Matlab %MATLAB Code to illustrate %eye eye(2,2) Output: ans = Diagonal Matrix 1 0 0 1 Plotting Commands: Commands UseaxisSets axis limitgridDisplays grid linesplotGenerates xy plottitle Puts title at top of the plotclose Closes current plotbarCreates bar chartprint Prints the plot / saves the plotfigureOpens a new figure windowClose allCloses all plots Example1: Matlab % MATLAB Code to illustrate %plot x = linspace(0,20) y = cos(x) plot(x,y) Output: Example 2: Matlab %MATLAB Code to illustrate %grid x = linspace(0,20) y = cos(x) plot(x,y) grid on Output: Comment More infoAdvertise with us Next Article MATLAB Commands D deepthikamath Follow Improve Article Tags : Software Engineering MATLAB Similar Reads Comments in MATLAB Comments are generic English sentences, mostly written in a program to explain what it does or what a piece of code is supposed to do. More specifically, information that programmer should be concerned with and it has nothing to do with the logic of the code. They are completely ignored by the compi 2 min read What is a Command? A command typically refers to an order given to a computer program or operating system to perform a specific task. It's usually entered via a command line interface or a terminal. Commands can vary widely depending on the context, the operating system being used, and the specific program or utility 5 min read MATLAB - Loops MATLAB stands for Matrix Laboratory. It is a high-performance language that is used for technical computing. It was developed by Cleve Molar of the company MathWorks.Inc in the year 1984.It is written in C, C++, Java. It allows matrix manipulations, plotting of functions, implementation of algorithm 2 min read Functions in MATLAB Methods are also popularly known as functions. The main aim of the methods is to reuse the code. A method is a block of code which is invoked and executed when it is called by the user. It contains local workspace and independent of base workspace which belongs to command prompt. Let's take a glance 5 min read Factorial in MATLAB MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. In this article, we'll be calculating the factorial of a number n using MATLAB's built-in function 'factorial(number)'. Factorial:The 1 min read Like