You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To display the 5th number of this vectors use `v(5)`. _Beware that ocatve is 1 based_.
Displaying a range of numbers use `v(3:5)` to display the 3rd, 4th, and 5th number.
### Useful functions
`help _function name_` will give you the man page of this function.
`ones(x [, y])` creates a matrix with ones. If only `x` is provided it is a squared matrix of size `x`. If `y` is provides it has the size x cross y.
`zeros(x [, y])` behaves the same as `ones()` but will give a zero-matrix.
`rand(x [, y])` Return a matrix with random elements uniformly distributed on the interval (0, 1).
`randn(x [, y])` Return a matrix with normally distributed random elements having zero mean and variance one. The arguments are handled the same as the arguments for `rand`.
`hist(x [, y])` Produce histogram counts of plots. `y` is the number of buckets.
`eye(x [, y]])` Produces an identity matrix.
`size(A [, DIM])` Return the number of rows and colums of A.
`DIM = 1` number rows
`DIM = 2` number columns
`length(A)` Return the _length_ of the object A. For Matrix objects, the length is the number of rows or columns, whichever is greater (this odd definition is used for compatibility with MATHLAB).
log(a) % natural logarithm
abs(a) % absolute value
sign(a) % signum function
exp(a) % compute e^a
`who` Lists currently defined varibales matchin the given pattern.
`whos` Provide detailed information on currently defined variables.
`sum(a)`, `sum(A,1)` sums up all columns.
`sum(A,2)` sums up all rows
`prod(a)` takes the product of each column
`floor(a)` rounds down
`ceil(a)` rounds up
`clear` will clear all variables or only the ones who are named.
### Save and Load Data
You can save and load data in octave easily with the two commands `save` and `load`.
To save a specific variable `v` to the file `filename.dat`
save filename.dat v; % save data of v in binary format
save filename.txt v --ascii % save data of v in readable version
Loading data is as simple as saving.
% both are equivalent
load filename.dat
load('filename.dat')
The file will be saved in the current directory and will be loaded from the current dir.
### Matrixes
Let `A` be the matrix: `A = [1 2; 3 4; 5 6]`
A =
1 2
3 4
5 6
The semicolon indicates a new row and a space or comma is a new column. Instead of typing a semicolon it is also possible to hit `enter`.
#### Display Data
% show number in first row and second column
>> A(1,2)
ans = 2
% show second row: colon means 'all'
>> A(2,:)
ans =
3 4
% show second column
>> A(:,2)
ans =
2
4
6
#### Assign new Data
% replace second column by 10, 11, and 12
>> A(:,2) = [10,11,12]
% in this case it doesn't matter if comma or semicolon is used
>> A(:,2) = [10;11;12]
#### Concatinating Matrixes
>> B = [20 21; 22 23; 24 25]
>> C = [A B] % A B
ans =
1 2
3 4
5 6
20 21
22 23
24 25
>> D = [A; B] % A append B
ans =
1 2 20 21
3 4 22 23
5 6 24 25
#### Transpose a matrix or a vector
>> A'
ans =
1 3 5
2 4 6
#### max values and find()
>> max(magic(4)) % returns a 1x4 vector with max-values per column