Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.

Slides:



Advertisements
Similar presentations
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Advertisements

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.
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.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to Programming with C++ Fourth Edition
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
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.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Matlab intro The Environment
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.
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
1 Introduction to MATLAB MATLAB is all of the following: 1.Computational environment 2.Plotting software 3.Programming language Typical applications: 1.Calculations.
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,
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.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
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.
Vectors Lecture 11: Supporting Material Dr Kathryn Merrick Tuesday 7 th April, 2009.
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
>> 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.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
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,
(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.
Array Operations ENGR 1181 MATLAB 4.
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.
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.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
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.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
An Introduction to Programming in Matlab Emily Blumenthal
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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
Linear Algebra review (optional)
Manipulating MATLAB Matrices Chapter 4
Vectors and Matrices I.
Communication and Coding Theory Lab(CS491)
Arrays and Matrices in MATLAB
Array Creation ENGR 1181 MATLAB 02.
Linear Algebra review (optional)
Matrices in MATLAB Dr. Risanuri Hidayat.
EECS Introduction to Computing for the Physical Sciences
Working with Arrays in MATLAB
Presentation transcript:

Array Creation ENGR 1187 MATLAB 2

Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays

Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays

Arrays: What are they?  Before we answer that, let’s think about how a computer stores and organizes data. In computer science, a data structure is a particular way of organizing data in a computer so that it can be used efficiently. MATLAB has it’s own data structure (way of organizing data).  An array is a data structure that contains a group of elements of the same data type.

Arrays: What are they?  In this class we’re going to work with one-dimensional & two- dimensional arrays.  We can refer to the size of arrays as an M x N array. M = number of rows. N = number of columns.  For example: >> x = 5; % Enter this in the command window The variable x is now a 1 x 1 scalar array.  We can take advantage of MATLABs ability to easily create and manipulate various sizes of arrays to analyze large data sets.

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 Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays

 A vector is an array that contains multiple elements in either a single row OR a single column.  A vector is referred to as a one-dimensional array.  For example: What is a vector? [ ] Row Vector: 1 Row by 4 Columns Column Vector: 4 Rows by 1 Column

Row Vectors vs. Column Vectors  When creating a vector you need to choose which type to create.  This will depend on the type of calculations you need to do. i.e., Compute sin(x) where x goes from 0 to 360 degrees.  >> x = 0 : 360; % Generate a row vector using colon operator  >> y = sind(x); % Remember, in degrees we use “sind”, not “sin”  >> plot(x,y); % We’ll learn more about visualization later in the semester.

Row Vectors vs. Column Vectors  Note: Because x is a row vector MATLAB will return y as a row vector as well.

Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays

What is a matrix?  A matrix is a two-dimensional, rectangular array of numbers.  For example: Rows 4 Columns Rows 5 Columns

What is a matrix?  There are many ways matrices can be used to represent data.  For 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

What is a matrix?  Another Example: Using multiple matrices for a 3D representation of the earth’s surface (Digital Elevation Models).  Requires 3 two-dimensional matrices 1 matrix for all longitudinal coordinates (i.e., X ) 1 matrix for all latitude coordinates (i.e., Y) 1 matrix for all elevation values (in feet or meters) (i.e., Z)

Yellowstone DEM Google Earth ImageMATLAB Display of DEM

Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays

Basic Approach (for small arrays): Row Vectors  We could make a row vector that consists of even numbers from 2 to 10: >> x = [ ]; % Without commas OR >> x = [2,4,6,8,10]; % With commas  Vectors can only be created using “[ ]” brackets.  Elements can be separated by spaces OR commas.

Basic Approach (for small arrays): Column Vectors  We could make a column vector that contains average temperature data for four months: [ ] : >> x = [28; 33; 42; 51]; % With semi-colons  Must use “[ ]” brackets.  Elements can be separated by semi-colons OR using by an 'enter‘.

 The most basic approach for creating a matrix is combining row and column vector syntax. For example: >> mat = [ ; ; ] Basic Approach (for small arrays): Matrices Row 1Row 2 Row 3

MATLAB Operators  Larger arrays can be created easily in MATLAB using the colon ( “:” ) operator. Syntax:  x = first_value : last_value; (i.e., >> x = 1 : 10; )  Assumes a spacing of 1  y = first_value : spacing : last_value; (i.e., >> y = 2 : 2 : 10;)  Specify the spacing between elements Note: This always produces a row vector!

MATLAB Operators  How can we easily create a column vector? The transpose operator ( Denoted by an apostrophe ‘ ). Syntax:  >> x = ( 1 : 10 )’ ;  >> y = ( 2 : 2 : 10 )’ ; Parenthesis are required for the transpose operator to work correctly.  The transpose operator can be used more generally on either type of vector ( Can be used on matrices too ).

MATLAB Functions  MATLAB has built-in functions for creating arrays. linspace: Generates linearly spaced vectors  Syntax: y = linspace(x1, x2, N)  x1 = start value; x2 = end value; N = number of element zeros: Generates an array of all zeros  Syntax: X = zeros(m,n) NOTE: Other input options are available >> help zeros  m = number of rows; n number of columns ones: Generates an array of all ones  Syntax: X = ones(m,n) NOTE: Other input options are available >> help ones  m = number of rows; n number of columns

Recap  Given the following array creations what is the size of each array? >> v1 = [ ]  Row vector of size [1 x 4] >> v2 = linspace(0, 10, 15)’  Column vector of size [15 x 1] >> v3 = [ ; linspace(0, 1, 4) ]  Matrix of size [2 x 4]

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.