Home » MATLAB

Commands in MATLAB

In this tutorial, we are going to learn about the commands, special variables, constants, display formats, input/output formats in MATLAB.
Submitted by Alok Kumar, on September 10, 2019

Commands are the instructions entered by the user to any software or system to perform certain work in the same way we can give commands to MATLAB software to the mathematical operation in the system by the help of various operators and commands.

Mainly command is entered in the command window by typing it at the MATLAB prompt ">>" on the command window.

MATLAB provides various commands for managing different work or session. Some commands and there working is shown below:

Commands for general purposes

Operators and special characters

Operator Description
+ Plus or addition operator
*Scalar and multiplication
-Minus or subtraction operator
^Matrix exponential operator
\Left-division operator
/Right-division operator
()Parentheses
[]Brackets

Above are some mathematical operators which are commonly used in Matlab to perform certain operations.

The following are commands that can be used to eliminate variable or are used to obtain the information about the variables that we have already created in the program.

When these commands are typed in the command window and enter key is pressed, they either provide information, or they perform a task as listed below.

CommandDescription
Clear Removes all variables from the memory.
Clear x y zRemoves only variables x, y, and z from the memory.
clcClears command window
exitChecks for existence of file or variable
globalDeclares variables to be global
quitStops Matlab
whoLists current variables
whosLists current variables

Special variables and constants

ans Most recent answer
eps Accuracy of floating point precision
i,j The imaginary unit
Inf Infinity
NaN Undefined numerical result
pi The number 22/7

Display formats

Command Description Example
format short Fixed-point with 4 decimal digits for:
0.001<=number<=10000
Otherwise display format short e.
>> 290/7
= 41.4286
format long Fixed-point with 14 decimal digits for:
0.001<=number<=100
Otherwise display format long e.
>> 290/7
= 41.42857142857143
format short e Scientific notation with 4 decimal digits. >>290/7
= 4.1429e+001
format long e Scientific notation with 15 decimal digits >>290/7
= 4.142857142857143e+001
format short g Best of 5-digits fixed or floating point. >>290/7
= 41.429
format long g Best of 15 digit fixed or floating point. >>290/7
= 41.428571428574
format bank Two decimal digits >>290/7
= 41.43

Input/output and formatting commands

disp Displays contents of an array or string.
fscanf Read formatted data from a file.
format Controls screen-display format.
fprintf Performs formatted writes to screen or files.
input Displays prompts and wait for input
; Supresses screen printing.

In the same way, there are various commands present in MATLAB like commands on the array, special matrices, matrix arithmetic as well as matrix commands for solving linear equations along with plotting commands which is basic XY plotting on x and y axis for graphical use.

So, MATLAB is full of command which is much more along with the insertion of tables, chats, and colors also, as it can also simulate the function created by a person.

Example:

Need to determine the number of years and months that correspond to t. Way to input commands in MATLAB is shown below,

    >>p = 5000; r = 0.085; ta = 17; n = 12;
    
    >>b=p*(1+r)^ta
        b=
        2.0011e+004
    
    >>t=log(b/p)/(n*log(1+r/n))
        t=
        16.3737
    
    >>year = fix(t)
        Years =
        16
    
    >>months=ceil((t-years)*12)
        Months=
        5

Above is shown how to determine the number of years and months that corresponds to t.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.