Unformatted text preview: x = 1:2:8; Is equivalent to x = [ 1 3 5 7 ]; you can leave out the increment if it is 1 For example y=1:4 is the same as y=[1 2 3 4] Accessing Individual Vector Elements
You can access specific locations in a vector just like C++:
a = [0 1 2 3 4 5 6 7 8 9] a(1) [0] a(8) [7] a(1:5) [0 1 2 3 4] a(4:10) [3 4 5 6 7 8 9] a(3:3:10) [2 5 8] Shortcut Expressions for Matrix Initialization
If you want a matrix to have all zeros or all ones you can use a builtin function. builtzeros(n) zeros(n, m) ones(n) ones(n, m) eye(n) eye(n, m) creates an n x n matrix of zeros creates an n x m matrix of zeros creates an n x n matrix of ones creates an n x m matrix of ones creates an n x n identity matrix creates an n x m identity matrix Shortcut Expressions for Matrix Initialization
You can use the size of a previous matrix as a template for a new matrix length(arr) returns the length of a vector or the longest dimension of a matrix size(arr) returns the rows and columns of an array x = [1 2 3; 4 5 6]; y = zeros(size(x)); Getting Data From the User
You can use the input function to prompt the user for input. val = input(`Enter a numb...
View
Full
Document
This note was uploaded on 05/04/2010 for the course ENGIN 101 taught by Professor Jeffringenberg during the Spring '07 term at University of Michigan.
 Spring '07
 JeffRingenberg

Click to edit the document details