Arrays and variables 1.Representing tables as arrays in MATLAB 2.Concept of array dimension 3.Correspondence of array dimension to rows and columns 4.Picking.

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

CS0007: Introduction to Computer Programming Arrays: Higher Dimensional Arrays.
Arrays.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Matrix Definition A Matrix is an ordered set of numbers, variables or parameters. An example of a matrix can be represented by: The matrix is an ordered.
Determinants. Determinant - a square array of numbers or variables enclosed between parallel vertical bars. **To find a determinant you must have a SQUARE.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
4-1 Matrices and Data Warm Up Lesson Presentation Lesson Quiz
You have to pay £87 per week for your rent. You have to pay the rent for 51 weeks of the year. How much will you pay over the year?
Box Method for Factoring Factoring expressions in the form of.
Matrix Multiplication The inner dimensions must be the same (or the number of columns in the first matrix is equal to the number of rows in the second.
13.1 Matrices and Their Sums
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
Module 6 Lesson 8. Objective Create arrays using square tiles with gaps.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
4.1 Using Matrices Warm-up (IN) Learning Objective: to represent mathematical and real-world data in a matrix and to find sums, differences and scalar.
Lookup Function (Think of a Book Index).  Need to fill based on what is in the these fields Array table.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
Step 1: Place x 2 term and constant into the box 2x 2 2 PROBLEM: 2x 2 + 5x + 2.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
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.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Section 9-1 An Introduction to Matrices Objective: To perform scalar multiplication on a matrix. To solve matrices for variables. To solve problems using.
Writing Headlines. Key Concepts 0 What is a headline? 0 What should a headline look like? 0 What are the different types of headlines?
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Arrays.
MATRIX A set of numbers arranged in rows and columns enclosed in round or square brackets is called a matrix. The order of a matrix gives the number of.
Digital Image Processing. Converting between Data Classes The general syntax is B = data_class_name (A) Where data_class_name is one of the names defined.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
14.1 Matrix Addition and Scalar Multiplication OBJ:  To find the sum, difference, or scalar multiples of matrices.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Unit 3: Matrices. Matrix: A rectangular arrangement of data into rows and columns, identified by capital letters. Matrix Dimensions: Number of rows, m,
Precalculus Section 14.1 Add and subtract matrices Often a set of data is arranged in a table form A matrix is a rectangular.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
Designed by Victor Help you improve MATRICES Let Maths take you Further… Know how to write a Matrix, Know what is Order of Matrices,
Box Method for Factoring
Box Method for Factoring
Multiplication.
Column addition and subtraction
Column addition and subtraction
Introduction to Matrices
Column addition and subtraction
Multiplying Matrices.
Determinants.
Unit 3: Matrices
2.2 Introduction to Matrices
Communication and Coding Theory Lab(CS491)
Array Creation ENGR 1181 MATLAB 02.
Matrices.
Column addition We have not worked on column addition for a while
Relational Operators.
Date: Column addition Success criteria Start on the right-hand side
3.6 Multiply Matrices.
Matrices in MATLAB Dr. Risanuri Hidayat.
Date: Column subtraction
Date: Column subtraction
Matrices.
Date: Column subtraction
Date: Column addition Date: Column addition Date: Column addition
Presentation transcript:

Arrays and variables 1.Representing tables as arrays in MATLAB 2.Concept of array dimension 3.Correspondence of array dimension to rows and columns 4.Picking out individual items in an array 5.Picking out individual rows and columns 6.Creating variables to hold array values 7.Entering array data

Tabular data and arrays Tables are most common data representation MATLAB represents tables using arrays We will mainly work with 2D arrays (rows × columns) YearCases (in thousands) Dim 2 (columns) Dim 1 (rows)

MATLAB arrays Name the array to access (e.g., assign to a variable) Access an item in the array by its position Row and column numbers start with Dim 2 (columns) Dim 1 (rows) (1) (2) (1) (2) (3) (4) (6) (5) disease EXAMPLE: An array called disease represents a table of data. The first column contains the year, and the second column contains number of cases of the disease (in thousands) for that year. disease is a 6 x 2 array (it has 6 rows and 2 columns)

Picking out an item from a table Address items by name(row, col) Usually you create a new variable to hold value Make up a variable name that is meaningful Use assignment (=) to put a value in the variable Dim 2 (columns) Dim 1 (rows) (1) (2) (1) (2) (3) (4) (6) (5) disease EXAMPLE: Designate the number of cases in 1931 (e.g., the value 26.5): disease(1, 2) EXAMPLE: Create a new variable holding number of cases in 1931: cases1931 = disease(1, 2);

Picking out row or column from a table Address items by name(row, col) Use : to designate “all rows” or “all columns” Make up a variable name that is meaningful Use assignment (=) to put a value in the variable Dim 2 (columns) Dim 1 (rows) (1) (2) (1) (2) (3) (4) (6) (5) disease EXAMPLE: Designate column 2 of disease (e.g., all rows for column 2) disease(:, 2) EXAMPLE: Create a new variable for number of cases of the disease: cases = disease(:, 2);

Creating a table from some values Enter values left to right, top to bottom Use square brackets to enclose the values ([ ]) Commas separate values on same line Semicolons separate rows The... designates that code continues on next line Dim 2 (columns) Dim 1 (rows) (1) (2) (1) (2) (3) (4) (6) (5) disease EXAMPLE: Create a variable for the first three rows of disease: myCases = [1931, 26.5; , 10.3; , 36.2];

Meaning of assignment (=) The statement A = B does NOT mean A and B are equal The left hand side (A) is a location designated by a variable The right hand side (B) is evaluated and assigned to the variable EXAMPLE: The assignment statement: cases = disease(:, 2); splits out the second column of array designated by disease and creates a new array designated by the cases variable holding a copy of the column.