Exam 3 Review

# Firstincrementlast x 128 is equivalent to x 1 3 5

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

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 built-in 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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern