E7_lecture4_F08_2D_arrays - 1 E7: INTRODUCTION TO COMPUTER...

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

View Full Document Right Arrow Icon
1 E7: INTRODUCTION TO COMPUTER ROGRAMMING FOR SCIENTISTS AND PROGRAMMING FOR SCIENTISTS AND ENGINEERS Lecture Outline 1. Two-dimensional arrays 2. Polynomials opyright 2007 Horowitz Packard This work is licensed under the Creative Commons Attribution- hare E7 L3 Copyright 2007, Horowitz, Packard. This work is licensed under the Creative Commons Attribution Share Alike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 2 Introduction to arrays xamples: 2 imensional arrays Examples: 2-dimensional arrays (2 rows, 3 columns) 1.2 3.2 1.0 3.1 92 0.0 d !" # $% ' &' (3 rows, 3 columns) 146 725 e # % 843 E7 L3 3 2-dimensional arrays dimensional arrays rectangular arrangement of numbers is called an A rectangular arrangement of numbers is called an array. Example: 3-by-2 array. 1 " (3 rows, and 2 columns) 21 3 (3,1) element 23 5 % (3 rd row, and 1 st column) 45 Matlab2-D convention: Row Column) E7 L4 ( Row , Column) 4 Creating arrays Creating arrays – manual construction manual construction xample 1: Example 1: > A [21; 3;45] 3 >> A =[21; -23;45] A # ' A = 2 1 -2 3 4 5 The semicolon is sed to demark ws E7 L4 used to demark rows
Background image of page 1

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

View Full DocumentRight Arrow Icon
5 Creating arrays Creating arrays – manual construction manual construction xample 1: Example 1: >A = [ 1 >>A = [ 21 -2 3 4 5 ] A = 1 carriage return <CR> is also used to emark ws -2 3 5 E7 L4 demark rows 45 xample 1: 6 Creating arrays Creating arrays – manual construction manual construction Example 1: >A [ ; ;4] [1; 3 ;5] ] >>A = [[ 2; -2;4] , [1; 3 ;5] ] rst column econd column first column second column A = -2 3 5 E7 L4 xample 1: 7 Creating arrays Creating arrays – manual construction manual construction Example 1: >A [ ; >>A = [[ 2; -2;4] [1; 3 ;5] ] rst column dl first column second column A = comma is not needed -2 3 5 E7 L4 xample 1: 8 Creating arrays Creating arrays – manual construction manual construction Example 1: > A [ ; ;4] >> A = [[ 2;-2;4] . .. [ 1 ; 3 ; 5 ] ] A = -2 3 5 “...” - allows a new line without a <CR> E7 L4
Background image of page 2
xample 1: 9 Creating arrays Creating arrays – manual construction manual construction Example 1: >>A = [[ 2;-2 ;4 ] [ 1 ; 3 ; 5 ] ] A = 2 -2 CR> means a 4 1 <CR> means a new row 3 5 E7 L4 zeros, ones and rand commands 10 > ( 2 2 ) >> A = ones(2,3) A = >> B = zeros(2,2) B = 1 1 1 0 0 0 1 1 1 00 Matlab 2-D convention: >> r = 3*ones(1,5) r = (rows, columns) E7 L3 3 3 3 3 3 Array concatenation 11 >> A = ones(2,3) A = >> B = zeros(2,2) B = 1 1 1 0 0 0 1 1 1 >> C = [ A B ] C = 1 1 1 0 0 E7 L3 1 1 1 0 0 Array concatenation 12 C is the array formed by stacking A “next to” B Once constructed, C does not “know” that it came from two arrays.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/01/2009 for the course ENGLISH 7 taught by Professor Sengupta during the Spring '09 term at University of California, Berkeley.

Page1 / 11

E7_lecture4_F08_2D_arrays - 1 E7: INTRODUCTION TO COMPUTER...

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

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