12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

u(1:3)ans =0.9218 0.7382 0.1763You can also use a variable as a subscript:>> i = 1:3;>> u(i)ans =0.9218 0.7382 0.1763Two dimensional matrices are indexed the same way, only you haveto provide two indices:>> a = [1 2 3;4 5 6;7 8 9]a =1 2 34 5 67 8 9>> a(3,2)ans =8>> a(2:3,3)ans =69>> a(2,:)ans =4 5 6>> a(:,3)ans =369The last two examples use the colon symbol as an index, which matlabinterprets as the entire row or column.If a matrix is addressed using a single index, matlab counts theindex down successive columns:>> a(4)ans =2>> a(8)ans =6Exercise 1 Do you underst<strong>and</strong> the following result? (Answer onpage 183.)c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!