Insight Through Computing 18. Two-Dimensional Arrays Set-Up Rows and Columns Subscripting Operations Examples.

Slides:



Advertisements
Similar presentations
Arrays  An array is a collection of like elements.  There are many engineering applications that use arrays.  MATLAB ® stores data in arrays and performs.
Advertisements

Multidimensional arrays Many problems require information be organized as a two- dimensional or multidimensional list Examples –Matrices –Graphical animation.
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
1 2-D Arrays Overview l Why do we need Multi-dimensional array l 2-D array declaration l Accessing elements of a 2-D array l Declaration using Initializer.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
Insight Through Computing 22. Working with Image Files imread, imwrite, imshow, uint8, rgb2gray.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
Insight Through Computing 20. More on 2D Arrays And their connections to Cell arrays Structure arrays Character arrays.
Insight Through Computing 23. Working with Image Files Cont’d Filtering Noise Edge Detection.
Introduction to Programming with C++ Fourth Edition
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
Matlab Intro. Outline Matlab introduction Matlab elements Types Variables Matrices.
Matrices Write and Augmented Matrix of a system of Linear Equations Write the system from the augmented matrix Solve Systems of Linear Equations using.
MMG508.  Access Types  Tables  Relational tables  Queries  Stored database queries  Forms  GUI forms for data entry/display  Reports  Reports.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Maximum-sum contiguous subarray Prudence Wong.
Matrix Algebra. Quick Review Quick Review Solutions.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
4-1 Matrices and Data Warm Up Lesson Presentation Lesson Quiz
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Matlab Chapter 2: Array and Matrix Operations. What is a vector? In Matlab, it is a single row (horizontal) or column (vertical) of numbers or characters.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
2 dimensional arrays Steven Wood ©2005. Arrays dimensions Java allows arrays with many subscripts 2-D examples Chess board Excel spreadsheet.
ARRAYS 1.Basic Ideas 2.The Array Type 3.Processing Arrays 4.Parallel Arrays 5.Two-dimensional Array 6.Arrays as Parameters.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
 Pearson Education, Inc. All rights reserved Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Section 9.4 Systems of Linear Equations: Matrices
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
1 Data Structures CSCI 132, Spring 2014 Lecture 32 Tables I.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
1 Topic: Array Topic: Array. 2 Arrays Arrays In this chapter, we will : Learn about arrays Learn about arrays Explore how to declare and manipulate data.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
L23. Working with Image Files imread, imwrite, imshow, uint8, rgb2gray.
Unit 1 MATRICES Dr. Shildneck Fall, WHAT IS A MATRIX? A Matrix is a rectangular array of numbers placed inside brackets. A Matrix is a rectangular.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Arrays.
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
Two-Dimensional Arrays and Matrices ELEC 206 Computer Applications for Electrical Engineers.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Arrays. Arrays are objects that help us organize large amounts of information.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Precalculus Section 14.1 Add and subtract matrices Often a set of data is arranged in a table form A matrix is a rectangular.
Prof. Amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
CS1100 Computational Engineering
Array and Matrix Functions
L19. Two-Dimensional Arrays
Adjacency Matrices and PageRank
ENERGY 211 / CME 211 Lecture 11 October 15, 2008.
Applied Discrete Mathematics Week 4: Functions
Presentation transcript:

Insight Through Computing 18. Two-Dimensional Arrays Set-Up Rows and Columns Subscripting Operations Examples

Insight Through Computing 2-d array: matrix An array is a named collection of like data organized into rows and columns A 2-d array is a table, called a matrix Two indices identify the position of a value in a matrix, e.g., mat(r,c) refers to component in row r, column c of matrix mat Array index starts at 1 Rectangular: all rows have the same #of columns c r

Insight Through Computing Simple Set-Up Examples >> A = [1 2 3; 4 5 6] A =

Insight Through Computing Simple Set-Up Examples >> A = zeros(3,4) A =

Insight Through Computing Simple Set-Up Examples >> A = floor(100*rand(5,5)) A =

Insight Through Computing Simple Set-Up Examples >> A = [zeros(3,2) [1;2;3]] A =

Insight Through Computing Simple Set-Up Examples >> A = [zeros(3,2) ; [1 2] ] A =

Insight Through Computing Rows and Columns A: A is a 3-by-4 array: 3 rows 4 columns. row 1 row 2 row 3 col 4 col 3 col 2 col 1

Insight Through Computing Subscripting A: Individual entries: A(3,2)

Insight Through Computing Subscripting A: An Entire Row: A(2,:)

Insight Through Computing Scaling a Row A: A(2,:) = 10*A(2,:) A: BeforeAfter

Insight Through Computing Subscripting A: An Entire Column: A(:,3)

Insight Through Computing Incrementing the Values in a Column A: A(:,3) = A(:,3) A: Before After

Insight Through Computing Subscripting A: A General Subarray: A(2:3,3:4)

Insight Through Computing Zeroing a Subarray A: A(2:3,3:4) = zeros(2,2) A: BeforeAfter

Insight Through Computing Classical Double Loop Set-Up A: for i=1:3 for j=1:4 A(i,j) = 10*j + i; end

Insight Through Computing Set-Up By Row A: A = []; for i=1:3 v = [ ] + i; A = [A ; v] end

Insight Through Computing Set-Up By Column A: A = []; for j=1:4 v = 10*j + [1;2;3]; A = [A v] end

Insight Through Computing Question Time A = [ 1 2 3; 4 5 6]; C = A(:,2); What the value of A(2,2)? A. 4 B. 5 C. 6

Insight Through Computing Question Time A = [ 1 2 3; 4 5 6]; A = A(1:2,2:3) What the value of A(2,2)? A. 4 B. 5 C. 6

Insight Through Computing Largest Value A: m = max(A) ; M = max(m) m:M: 83

Insight Through Computing Functions and 2D Arrays function alpha = Ave(A) % A is a 2D array. % alpha is the average of its % values > ( )/6

Insight Through Computing Need Built-In Function size function alpha = Ave(A) [m,n] = size(A); Add up all the numbers in the array. Store in s. alpha = s/(m*n); size(A) returns #rows and # columns

Insight Through Computing Refine… function alpha = Ave(A) [m,n] = size(A); s = 0; for i=1:m sRow = the sum of the values in A(i,:) s = s + sRow end alpha = s/(m*n);

Insight Through Computing sRow = the sum of the values in A(i,:) sRow = 0; for j=1:n sRow = sRow + A(i,j); end

Insight Through Computing function alpha = Ave(A) [m,n] = size(A); s = 0; for i=1:m s = s + sRow end alpha = s/(m*n); sRow = 0; for j=1:n sRow = sRow + A(i,j); end

Insight Through Computing Now Some More Involved Examples

Insight Through Computing Random Web N web pages N-by-N Link Array A. A(i,j) is 1 if there is a link on webpage j to webpage i Generate a random link array and display the connectivity.

Insight Through Computing Random Link Idea A(i,,j) = 1 with probability More likely to be a link if i is close to j.

Insight Through Computing function A = RandomLinks(n) A = zeros(n,n); for i=1:n for j=1:n r = rand; if i~=j && r<= 1/(1 + abs(i-j)); A(i,j) = 1; end

Insight Through Computing N = 20

Insight Through Computing 100 Web pages. Now display the links….

Insight Through Computing Line black as it leaves page j, red when it arrives at page i.