Octave Tutorial
Octave Tutorial
Octave Tutorial
Octave
Tutorial
Beginner Level
1. Matrix Operations
a. ones(n,m): Generates a (n X m) matrix of 1s. This is how you would do it in Octave
a. Defining range 1 to 5
3. Indexing
Let us define a (2 X 2) matrix S
b. To return the 1st row and both 1st and 2nd column
d. To return the 1st row and a range of columns (here between 1st and 2nd column)
4. Loading and Saving Data
Before loading the data, we must navigate to the directory where we want our data files to be
available. Octave supports both windows and unix commands for navigating to the working
directory.
b. Loading data and assigning it to variable using “load” command. Please note that
mydata.dat file should be present in your working directory. If not change your
working directory using “cd” command (>> cd insert_working_directory).
c. Creating a vector v and saving the data in the working directory using “save”
command
d. Please check your working directory for the file named “yourdata.dav”
5. Matrix Concatenation
a. Defining 2 vectors a & b
b. Concatenating 2 vectors
6. Plotting in Octave
Let us define a vector x
Let’s square the individual elements using “.” Function
a. Plotting the vector y using “plot” function. Please note in case of a warning message
or delay in getting the plot use “hold on” command.
c. Creating a scatter plot between y & x using “scatter” command. Note that “close”
command should be used for closing the plot.
d. Creating a histogram using “hist” function
e. Above uses default number of bins. To define the number of bins in the histogram as
30 in this example,
7. Boolean Operators
= Equal to
=
!= Not equal to
~= Not equal to
> Greater than
< Lesser than
> Greater than or equal to
=
< Lesser than or equal to
=
if(expression),
do something;
elseif((expression),
do something;
else
otherwise do this;
end;
for i = 1:10,
do something;
end;
while(expression),
do something;
end;