Octave: In-built functions (P1)

Octave similar to other language support inbuilt functions. Few of inbuilt functions are listed with examples below.

 

  1. who: Displays all variables currently in memory.
    • Example:
      • Step 1: m1 = [1 2;3 4] This creates a m1 variable in memory and assigns 2×2 matrix.
      • Step 2: m2 = m1 .^2. This results in a matrix where each element of matrix is squared [1 4; 9 16] and result is assigned to m2.
      • Step 3: m1 + m2. Matrix addition[2 6; 12 20]
      • who(). This function display all variables in memory. Variables displayed are “ans”,”m1” &”m2”
  2. clear: Clears variable(s) from memory.
    • Example:
      • Step 1: m1 = [1 2;3 4] This creates a m1 variable in memory and assigns 2×2 matrix.
      • Step 2: m2 = m1 .^2. This results in a matrix where each element of matrix is squared [1 4; 9 16] and result is assigned to m2.
      • Step 3: m1 + m2. Matrix addition[2 6; 12 20]
      • who(). This function display all variables in memory. Variables displayed are “ans”,”m1” &”m2”
      • clear m1. This clears variable m1 from memory
      • clear() to remove all variables from memory.
  3. pwd(): Present Working Directory
    • Example:
      • Step 1: pwd() This results in current working directory. “C:\Users\<User Name>” is default working directory.
  4. cd(): Change Directory:
    • Example:
      • Step 1: pwd() This results in current working directory. “C:\Users\<User Name>” is default working directory.
      • Step 2: cd(“D://Readiness//Data Science//Machine Learning//Octave Tutorials”) will change present working directory to new path.
      • Step 3: pwd(). This displays new modified path of present working director
  • Note:
    • Octave is case sensitive. “who” is different from “WHO” or “Who”
    • “ans” is a default variable that is created by Octave runtime to store result of any computation. It stores only last result of any computation and is overwritten by next operation. Value of result of computation can be accessed by “ans” variable.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s