MATLAB / Octave tutorial-----Chapter 1------Constants and Variables



CHAPTER 1: MATLAB / Octave basics


At the very outset, let us see how the first opening window(also called terminal) of both the softwares look like:


MATLAB opening window


 Octave opening window

If you look at both the windows you’ll see that all the toolbars are same, the interfaces are identical. So, let’s quickly learn a few commands and see the output from each.
Please follow these steps:
a)     Type the command on the prompt. 
b)    Press enter.
1. clc: This command is used to clear the terminal screen. It is implemented like so:

 Using 'clc' command

From now onwards, we shall execute all commands in octave. All commands executed in octave runs exactly in the same way in MATLAB. All files in MATLAB and Octave are saved with the extension .m.


2.     Playing with constants:
All numbers written on the prompt are echoed on the screen as shown in the figure.

 Playing with constants

 3.    Playing with variables:

 It is very easy to use variables in MATLAB/Octave. Unlike C/Java, etc., there is no need to specify any data type. MATLAB / Octave determines the same on its own. Hence, we just assign  a value to a variable like so:


Playing with variables

Thus we see how we have used variables in MATLAB / Octave. String or characters can be represented using both single and double quotes. Please note that, whenever you type anything on the prompt, it gets echoed after you press enter key. However, this can be avoided by ending the line with a semicolon(;) as shown below:

Statements ending with semicolon does not echo the lines typed




4.    Comment lines:
      The '%'  sign is used to write single line comments. To note, multi-line comments are not present in MATLAB / Octave.

Use of comment line

So, here we come to the end of this tutorial. In the next tutorial we will know the arithmetic and logical operators and also learn to create MATLAB scripts.

Thanks for reading the entire article.....Happy learning.......

   




Comments

  1. Please like and follow my Facebook page to keep yourself updated with the lessons: https://www.facebook.com/tutorformatlab/

    ReplyDelete

Post a Comment

Popular posts from this blog

MATLAB / Octave Tutorial : Generating various signals

MATLAB / Octave Tutorial----Chapter 3-----Visualising the data(Part 3)

MATLAB / Octave Tutorial-------Chapter 2------Arithmetic and Logical operations