MATLAB/GNU Octave Quick Reference Sheet

MATLAB/GNU Octave Quick Reference Sheet

MATLAB/GNU Octave quick reference sheet A = zeros(<N>[,M]) Create a N × M matrix with Plotting and visualization Last revision: February 21, 2013 values 0 A = ones(<N>[,M]) Create a N × M matrix with In the following, n and m can be single values or vectors. By Anders Damsgaard Christensen, values 1 figure Create new figure window Plot vector y as a function of x [email protected], http://cs.au.dk/~adc. A = rand(<N>[,M]) Create a N × M matrix with plot(x,y) The < > symbols denote required arguments, [] args. are optional. uniformly distr. values in [0; 1[ with a line The bracketing symbols should not be written. A = randn(<N>[,M]) Create a N × M matrix plot(x,y,'*') Plot vector y as a function of x with normal (Gaussian) distr. with points values with µ = 0; σ = 1 plot(x,y,'*-') Plot vector y as a function of x with a line and points General session control semilogx(x,y) Plot vector y as a function of x, with x on a log scale whos List all defined variables semilogy(x,y) Plot vector y as a function of x, Arithmetic and standard functions clear Delete all defined variables with y on a log scale clc Clear home screen loglog(x,y) Plot vector y as a function of x, on edit <file>[.m] edit file, create if it doesn't In general, the number of elements returned equal the dimen- a loglog scale sions of the input variables. a*b = ab, a/b = a , a**b = ab, already exist p b p hist(x) Plot a histogram of values in x b save '<filename>' Save all variables to <file- a%b: remainder, sqrt(a) = a, a**(1/b) = a, abs(a) grid Show numeric grid in the plot name>.mat = jaj, log(a,b) = logb(a) sin(a) = sin(a), background load '<filename>' Load variables from <file- M.*N: element-wise multiplication of two vectors/matrices axes equal Set a 1:1 aspec ratio on the plot axes name>.mat M*N: multiplication of two vectors/matrices title('bla') Set a plot title help <command> Quick help on command A(:): show matrix as vector xlabel('bla') Set x-axis label doc <command> Extensive help on command A': Transpose of vector/matrix C=[A;B]: Concentrate two vectors/matrices size(A): Dimensions of vector/matrix Custom functions sum(A): Column sum of vector/matrix elations: ==, ~=, >, <, <=, >= Variables inv(A): Inverse of matrix Conditional structures: det(A): Determinant of matrix When assigning variables, the values will be dis- if expr ...[elseif ...] [else ...] end Anb: For a matrix A and col. vector b find solution x to Ax = b played. This can be suppresed by adding the suffix Iteration structures: for var=expr ... end ; Constants: pi = π, e = e, i = i, inf = 1 ans Value of last calculation Function syntax: x = 1 Define variable x to be a scalar function [out1, ...] = name (par1, ...) with value 1 ... x = y Set x equal to y end v = [1,2,3] Define variable v to be a row Vector/matrix slicing vector with values 1 2 3 v = [1;2;3] Define variable v to be a In the following, n and m can be single values or vectors. MATLAB reference manual column vector v(<n>) The n-th value of vector v http://www.mathworks.se/help/matlab/index.html M = [1,2,3;4,5,6] Define variable M to be a v(1,<n>) The 1st to n-th value of vector v 1 2 3 GNU Octave reference manual matrix with values 4 5 6 The n-th value to the end of v(<n>,end) https://www.gnu.org/software/octave/doc/ v = <s>[:st]:<e> Create a row vector vector v interpreter/ with values from s M(<n>,<m>) The n; m-th value of matrix M to e with a step M(<n>,:) The n-th row of matrix M MATLAB/GNU Octave wikibook size of st M(<n>,:) The n-th row of matrix M https://en.wikibooks.org/wiki/MATLAB_ v = linspace(<s>,<e>[,st]) Create a row vector I = find(X > 2) Find indexes in X where the Programming/GNU_Octave with values from value is greater than 2 s to e with st Introduction to MATLAB intermediate values www.mathworks.com/moler/intro.pdf.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    1 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us