Home » MATLAB

Syntax in MATLAB

MATLAB Syntax: Here, we are going to learn about the syntax of MATLAB, and notes for working in the command window.
Submitted by Alok Kumar, on September 09, 2019

The syntax is the method by which the programmer give various commands to the system or the software. These commands are given to perform the specific task like.

In C OR C++, we give a command like #include<stdio.h> ,as it is giving command to the compiler to add the header file name stdio.h to the program or to execute it in the same way there are various syntax present in the MATLAB to give instruction to the software to perform the specific tasks.

First, when we open the MATLAB software it seems very complex to use as a calculator but we can easily use the software if we know the set of rules through which we can easily handle it.

Notes for working in the command window

  1. To type a command the cursor must be placed next to the command prompt (>>).
  2. Once a command is typed and the enter key is pressed, the command is executed. However, only the last command is executed. Everything executed previously is unchanged.
  3. Several commands can be typed in the same line. This is done by typing a command between the commands. When the enter key is pressed the commands are executed in order from left to right.
  4. It is not possible to go back to a previous line in the command window, make a correction, and then re-executed the command.
  5. A previously typed command can be recalled to the command prompt with the up-arrow key. When the command is displayed at the command prompt, it can be modified if needed and executed. The down-arrow key can be used to move down the previously typed commands.
  6. If a command is too long to fit in one line, it can be contained to the next line by typing the periods… (called an ellipsis) and pressing the enter key. The continuation of the command is then typed in the new line. The command can continue line after line up to a total of 4096 characters.

Way to execute the program in MATLAB

    Type a valid expression, 
    for example:
        6+6
    And press ENTER

When you click execute button or type CTRL+E, MATLAB executes it immediately and the result will return as,

    Ans =12

In the same way we can execute various commands like,

    4^5             power of 5 raised to 4
    Cos (pi/2)      cos of angle 90 degree
    567*678         first number multiplied to the second

Above are some ways to give the command to MATLAB software and then press ENTER or CTRL+E to execute and after pressing the execution button it will show the result.

MATLAB provides some special expressions for some mathematical symbols, like pi for 22/7, inf for infinity I (or j) for sqrt(-1).

There are also various symbols used in MATLAB which act as syntax like given below,

  1. (>>) The point from where we can start to write our program.
  2. (;) If a semicolon is typed at the end of a command the output of the command is not displayed. It is useful when the result is known.
  3. (%) When this symbol is typed at the beginning of a line, the line is designated as a comment.

Example to execute a program

    >> 7 + 8/2          % type and press enter %
    Ans: 11             % 8/2 is executed first %





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.