123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- BASICS:
- ";" after command supresses output of the result
- help cmd # writes help for cmd command
- lookfor str # search documentation for str
- pkg load package # load given package
- # comment
- v = [1, 3, 2] # creates vector
- m = [1, 2; 3, 4] # creates matrix
- v(1) # indexing (1-based), gets the first element
- v(2:5) # slice, get elements from 2 to 5
- v(end + 1) = 0 # append 0 to vector
- v(1:2:end) # select only odd elements of the vector
- m(1,1) # gets the matrix element at [1,1]
- m(1,:) # gets the first matrix row
- m(:,1) # gets the first matrix column
- 1:10 # creates a vector 1, 2, 3, ..., 10
- 1:0.5:10 # creates a vector 1, 1.5, 2, 2.5, ..., 10
- for a = v, disp(a); end # for loop, displays elements of vector "v"
- a = 0; while a < 10, a += 1, end # while loop
- if a == 10, disp(1); elseif a == 2, disp(2); else, disp(3); endif # if statement
- function r = f(x), if x > 0, r = 1; else r = 0; endif, endfunction # function definition
- f(3) # function call
- @f # function reference (can be given as an argument etc.)
- function [a,b] = f2(x), a = x; b = x; endfunction # function with multiple return values
- [X,Y] = meshgrid(1:10,1:10) # creates a 2D array as a function of x and y
- m2 = bsxfun(@f2,X,Y)
- OPERATORS:
- +
- -
- *
- /
- \ # reverse division (for matrices)
- ^
- ./ # element-wise divide
- .* # element-wise multiply
- .^ # element-wise power
- ' # transpose
- CONSTANT:
- pi
- e
- i
- inf
- nan
- realmax
- realmin
- BASIC FUNCTIONS:
- mod(x,y) Remainder, see also rem function.
- ceil(x)
- floor(x)
- round(x)
- sin(x)
- cos(x)
- tan(x)
- acos(x)
- asin(x)
- atan(x)
- sqrt(x)
- exp(x)
- abs(x)
- log(x) Natural logarithm (base = e).
- log10(x) Decadic logarithm (base = 10).
- sign(x)
- chdir(pathstr) Changes directory to "pathstr", e.g. "~/tmp".
- ADVANCED FUNCTIONS:
- arg(compl) Returns the argument of a complex number.
- conv(p,q) Multiplies two polynopmials represented by vectors of their coefficients.
- columns(mat) Returns the number of columns (width) of given matrix.
- dct(vec) Computes discrete cosing transform of given vector.
- dct2(mat) Computes 2D discrete cosing transform of given matrix.
- deconv(p,q) Divides two polynopmials represented by vectors of their coefficients.
- disp(what) Displays "what" according to currently set format (see format function).
- det(mat) Computes determinant of "mat" matrix.
- dot(vec) Computes a dot product.
- double(what) Converts given element to double (float) data type.
- eps(x) Machine-dependent, return floating point distance from x to the next number.
- eye(n) Creates n * n identity matrix.
- ezplot(f,dom,n) Plots a 2D curve defined by 2D function in given domain (vector [x_min,x_max,y_min,y_max]) with given number of points
- fclose(file) Closes file with given descriptor.
- fft(vec) Computes fast Fourier transform of given vector.
- fft2(mat) Computes 2D fast Fourier transform of given matrix.
- fliplr(mat) Flips matrix "mat" horizontally.
- flipud(mat) Flips matrix "mat" vertically.
- fopen(filename,mode) Opens file "filename" with given mode ('r','w' or 'a') and returns it descriptor.
- fplot(f,x1,x2,y1,y2,eps) Plots given function (use @ function reference) in given bounds and given precision
- idct(vec) Computer inverse cosine transform of given vector.
- idct2(mat) Computer inverse 2D cosine transform of given vector.
- ifft(vec) Computes inverse fast Fourier transform of given vector.
- ifft2(mat) Computes inverse 2D fast Fourier transform of given matrix.
- intersection(a,b) Creates an intersection of "a" and "b" sets.
- imread(path) Reads given image (can be filename or web url) into a matrix.
- imshow(img) Shows given image saved in matrix (datatype does matter for the display!).
- imwrite(img, path) Saves given image (which is stored as a matrix).
- int8(what) Converts given element to int8 data type.
- inv(mat) Computes matrix inverse.
- ismember(val,set) Checks if there is given value in given set (vector).
- linspace(from, to, num) Creates a vector of num values from "from" to "to".
- logspace(from, to, num) Creates a vector of num values from "from" to "to" in log space.
- mesh(z) Plots a 2D function (creates 3D plot) from a 2D matrix (array) of Z values
- numel(what) Returns the number of elements (length) of given object.
- ones(x,y) Creates x * y matrix filled with 1s.
- plot(vals) Plots "vals" vector as a function.
- plot(xvals, yvals) Plots points specified by "xvals" and "yvals" vectors.
- polyder(pol) Derivates polynomial represented by coefficients.
- polyfit(xvals,yvals,deg) Returns a polynomial of "deg" degree that best fits given data ("xvals", "yvals") - least square method.
- polyint(pol) Integrates polynomial represented by coefficients.
- polyout(vec,varstr) Displays a polynomial based on coefficients ("vec") and variable ("varstr", e.g. "x").
- polyval(vec,val) Evaluates a polynomial represented by coefficients ("vec") and variable value ("val").
- rand(x,y) Creates x * y matrix filled with random numbers from 0 to 1.
- rgb2gray(img) Converts given RGB image (saved in matrix) to grayscale.
- roots(pol) Finds roots of polynomial specified by its coefficients.
- rot90(mat) Rotates matrix "mat" by 90 degrees.
- rows(mat) Returns the number of rows (height) of given matrix.
- setdiff(a,b) Creates a difference of "a" and "b" sets.
- sort(vec) Sorts vector "vec".
- soundc(s,freq) Plays sound from vector "s" with "freq" sampling frequency.
- uint8(what) Converts given element to uint8 data type.
- union(a,b,) Creates an union of "a" and "b" sets.
- unique(vec) Removes duplicates from given vector.
- wavread(filename) Reads sound into vector from given file)
- wavwrite(s,freq,filename) Writes given audio vector to specified file.
- zeros(x,y) Creates x * y matrix filled with 0s.
- EXAMPLES:
- // apply low pass filter to an image (bigger than 20x20)
- img = rgb2gray(imread("test.png"))
- filter = resize(ones(20,20),rows(img),columns(img))
- imshow(uint8(idct2(dct2(img) .* filter)))
|