Commands
- % means comment
- ; suppresses print output
- 2^6(2 power 6)
- 1==2
- 1~=2 (is not equals)
- Logical operations
- 1&&0
- 1||0
- Vectors & Matrix
- A=[1 2; 2 3; 4 5]
- V=1:0.2:2 % Bunch of elements starts from 1, increments with 0.2, until you get up to 2
- V=1:6 %means 1 to 6
- ones(2,3) % 2 by 3 matrix with all elements as 1
- use try zeros, rand
- w=-6+sqrt(10)*(randn(1,10000))
hist(w) % generates histogram
hist(w,50) % histogram with 50 bins - I= eye(4) % 4*4 identity matrix
- A(2,:) % to fetch every element of 2nd row
- A(:,2) % 2nd column
- A([1,3],:) % every element in 1st and 3rd rows
- A=[A,[100;102;102]] % append another column vector
- A(:) % put all elements of A into single vector
- C=[A B] % concatenate 2 matrices
- C=[A; B] % concatenate 2 matrices by adding B to bottom of A
- A .* B %element wise multiplication
- A .^ 2 %element wise square
- 1 ./A %element wise reciprocal
- A' % transpose
- Octave variables in memory
- who/whos
- load
- load featuresx.dat %featuresx will be variable after loading
- clear featuresx % to clear the variable
- save hello.mat v % to save varaible v to hello.mat
- clear % clears all variables
- Function
- file extension .m
- function y= squareThisNumber(x)
y=x^2; - Octave searches for the file in the current directory
- Alternatively add path using command addpath();
- Octave function can return more than one value
No comments:
Post a Comment