matlab7 - 2-D Arrays (Matrices)Creating 2-D Arraysm = [ 11...

This preview shows pages 1–10. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

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

Unformatted text preview: 2-D Arrays (Matrices)Creating 2-D Arraysm = [ 11 12 1321 22 2331 32 33]; or>> m = [11 12 13; 21 22 23; 31 32 33]m =11 12 1321 22 2331 32 33Accessing Elements>> m(2, 1)ans =21>> m(2, 3)ans =23>> m(4, 1)??? Index exceeds matrix dimensions.Modifying Elements>> m(1, 3) = 1133m =11 12 113321 22 2331 32 33>> m(5, 6) = 56m =11 12 1133 0 0 21 22 23 0 0 31 32 33 0 0 0 0 0 0 0 0 0 0 0 0 56zeros function>> z = zeros(3)z =0 0 0 0 0 0 >> z = zeros(2, 4)z =0 0 0 0 0 0 >> zeros(1, 5) + (1:5)ans =1 2 3 4 5ones function>> ones(3)ans =1 1 11 1 11 1 1>> ones(1, 5) + (10:14)ans =11 12 13 14 15Getting Columns and Rows>> m = [11 12 13; 21 22 23; 31 32 33]m =11 12 1321 22 2331 32 33>> m(1, :)ans =11 12 13>> m(3, :)ans =31 32 33>> m(:, 2)ans =122232size function>> m = ones(4, 7);>> size(m)ans = 4 7>> [rsize csize] = size(m)rsize = 4csize = 7>> size(m(1, :))ans = 1 7>> length( m(1, :))ans = 7>> length( m(:, 1))ans = 4Programming Example : maxfunction maxval=mymax(m)maxval = -inf;for i = 1:length(v(:, 1))for j = 1:length(v(1, :))...
View Full Document

This note was uploaded on 10/29/2010 for the course CS 111 taught by Professor Stuff during the Fall '08 term at Bilkent University.

Page1 / 13

matlab7 - 2-D Arrays (Matrices)Creating 2-D Arraysm = [ 11...

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

View Full Document
Ask a homework question - tutors are online