16 - Matrices in MATLAB - Full

16 - Matrices in MATLAB - Full - Engineering101

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style Engineering 101 Matrices in MATLAB
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Quote of the Day - Mahatma  Gandhi An eye for an eye makes the whole world blind .
Background image of page 2
Shortcut Expressions for Matrix  n If you want to create a vector in which the terms are  regularly spaced you can use the colon operator. first:increment:last x = 1:2:8; Is equivalent to x = [ 1  3  5  7 ]; n you can leave out the increment if it is 1 n For example  y=1:4  is the same as  y=[1 2 3 4]
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Accessing Individual Vector Elements n 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]
Background image of page 4
Shortcut Expressions for Matrix  n If you want a matrix to have all zeros or all ones  you can use a built-in function. zeros(n) creates an n x n matrix of zeros zeros(n, m) creates an n x m matrix of zeros ones(n) creates an n x n matrix of ones ones(n, m) creates an n x m matrix of ones eye(n) creates an n x n identity matrix
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Shortcut Expressions for Matrix  n 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];
Background image of page 6
Getting Data From the User n You can use the input function to prompt the user for  input. val = input(‘Enter a number:’); n The user can enter a number or an array in brackets n If you need to get a string then val = input(‘Enter a string:’, ‘s’);
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Exercise n After these commands b=?
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 37

16 - Matrices in MATLAB - Full - Engineering101

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online