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.

Slides:



Advertisements
Similar presentations
2D Plots 1 ENGR 1181 MATLAB 12.
Advertisements

Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
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.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
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.
EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays.
Module 6 Matrices & Applications Chapter 26 Matrices and Applications I.
Matrix Mathematics in MATLAB and Excel
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
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.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
For Loops 1 ENGR 1181 MATLAB 8. For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane.
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.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Arrays & Vectors Week 5. The simplest form of the multidimensional array is the two-dimensional array. A two- dimensional array is, in essence, a list.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Working with Arrays in MATLAB
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Chapter 2 Creating Arrays Legend: MATLAB command or syntax : Blue MATLAB command OUTPUT : LIGHT BLUE.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
2D Plots 2 ENGR 1181 MATLAB 13. Plotting in the Real World 2D plots generated by MATLAB can be used in a variety of fields, including the one shown here,
While Loops ENGR 1181 MATLAB 10.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Array Operations ENGR 1181 MATLAB 4.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Array Accessing and Strings ENGR 1187 MATLAB 3. Today's Topics  Array Addressing (indexing)  Vector Addressing (indexing)  Matrix Addressing (indexing)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
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.
Logical Expressions ENGR 1181 MATLAB 6. Logical Expressions in Real Life Sorting objects in manufacturing processes can be accomplished automatically.
An Introduction to Programming in Matlab Emily Blumenthal
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
ECE 1304 Introduction to Electrical and Computer Engineering
Manipulating MATLAB Matrices Chapter 4
Chapter 2 Creating Arrays.
Vectors and Matrices I.
Communication and Coding Theory Lab(CS491)
Arrays and Matrices in MATLAB
Array Creation ENGR 1181 MATLAB 02.
Matrices in MATLAB Dr. Risanuri Hidayat.
EECS Introduction to Computing for the Physical Sciences
Presentation transcript:

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 are critical to structural design in areas like California where earthquakes are prevalent and dangerous in number of occurrences and magnitude. Array Creation In The Real World

Today’s Learning Objectives  After today’s class, students will be able to: Demonstrate proper convention for assigning arrays to a variable (e.g., space, semi-colons, colon operators, linspace function). Apply the transpose operator correctly.

What is a vector? A vector is an ordered list of several numbers and is a one-dimensional array  Row Vectors are horizontal: [ ]  Column Vectors are vertical: [ ]

Examples of Vectors We could make a vector that consists of even numbers from 2 to 10: [ ] We could make a vector contains average temperature data for four months: [ ]

Row Vectors vs. Column Vectors  You need to choose which type to create  This will depend on your data and the type of calculations you need to do  If you choose the 'wrong' type, you can transpose your row vector to a column vector, or a column to a row

Creating Row Vectors  A row vector is created by typing the elements inside square brackets [ ]  The elements are separated by commas OR spaces  You will likely assign your vector to a variable Remember to use valid variable names

Example: Creating Row Vectors >> vec1= [2, 4, 5] vec1 = >> vec2= [2 4 5] vec2 = 2 4 5

Creating Column Vectors  A column vector is separated by typing the elements inside square brackets [ ]  The elements are separated by a semicolon OR by an 'enter'  You will likely assign your vector to a variable Remember to use valid variable names

Example: Creating Column Vectors >> vec3= [1; 2; 3] vec3 = >> vec3= [1 2 3] vec3 =

Transposing Vectors  We can change a row vector into a column, or a column into a row  This is called transposing  We use a single quote to do this: ′

Example: Transpose Transpose the row vector A= [4 5 6] to a column: >> A= [4 5 6]; >> B = A′ B = 4 5 6

Vectors with Constant Spacing  Now we know how to enter known data, but there may be times when we want to create vectors with constant spacing  MATLAB can do this! We must know: first value, spacing, last value  It will look like this: [first value : spacing : last value]

Constant Spacing: Example 1 Create a list of odd numbers from 1 to 13: >> v1= [1: 2: 13] v1 =

Constant Spacing: Example 2 Create a vector called v3 with numbers divisible by 7 from -63 to -28. >> v3 = [ -63 : 7 : -28] v3 =

Constant Spacing: Example 3 Create a vector called v4 from 3.1 to 2.3 with a difference of 0.1 between the elements >> v4 = [ 3.1 : -0.1 : 2.3 ] v4 =

Constant Spacing Default Value If we do not specify a spacing value, MATLAB will default to a spacing value of 1: >> v2= [3:7] v2 =

Vector Creation: linspace()  The linspace() function lets us easily create a vector when we know three things about the vector: The first value The last value The number of elements in the vector linspace(first, last, number)

Example: Linspace Function Create a vector v5 with 6 elements, starting at 2.5 and ending at 3.5: >> v5 = linspace(2.5, 3.5, 6) v5 =

Example: Linspace Function Create a vector called v6 with 10 elements, starting at 99 and ending at 33: >> v6 = linspace(99, 33, 10) v6 =

Knowledge Check! Can you do this on your own? Create a row vector called B where the first element is 3, the second is 3 2, the third is 3 3, the fourth is 3 4.

Knowledge Check! Create a row vector called B where the first element is 3, the second is 3 2, the third is 3 3, the fourth is 3 4. >> B = [3 3^2 3^3 3^4] B =

Knowledge Check! … Is there any other way we could have created B? >> x=3; >> B= [x x^2 x^3 x^4] B =

Matrices: 2-D Arrays A matrix is a two-dimensional representation of a group of numbers containing rows and columns You can think of it as many row vectors stacked on top of one of one another

Matrix Example We have attendance data for number of absences of three students over 4 months. We can create this as a matrix: Student A Attendance  Student B Student C Jan Feb Mar Apr

Matrix Size  The size of a matrix is described by the number of rows and columns it contains.  A (m x n) matrix has m rows and n columns. Referred to as an “m by n” matrix Attendance is a 3 by 4 matrix Attendance

Creating a Matrix in MATLAB  A matrix is creating by typing the elements row by row inside square brackets [ ]  The elements within each row are separated by spaces  To start a new row, use a semicolon or the ′Enter′ key

Example: Creating a Matrix Let’s create the matrix for our attendance data: >> Attendance = [ ; ; ] Attendance =

Important Takeaways  Row vectors are horizontal with only 1 row  Elements are entered separated by commas or spaces  Column vectors are vertical with only 1 column, matrices have multiple columns and rows, rows are entered separated by a semicolon or ′Enter′ key  A matrix is a two-dimensional array. Its size is described as (m x n), or “rows by columns”

Preview of Next Class  Array Accessing and Strings Vector addressing and the use of an index Vector functions Addressing a range of elements in a vector Matrix addressing Extracting elements and sets of elements from a matrix

What’s Next?  Review today’s Quiz #02  Open the in-class activity from the EEIC website and we will go through it together.  Then, start working on MAT-02 homework.  Before next class, you will read about accessing arrays and how MATLAB recognizes strings of text.  Accessing arrays means finding items within arrays to use those values for calculations, change the values, or add new items to the array.