Array Creation ENGR 1187 MATLAB 2

Similar documents
Array Creation ENGR 1181 MATLAB 2

Array Accessing and Strings ENGR 1181 MATLAB 3

Array Accessing and Strings ENGR 1187 MATLAB 3

ENGR 1181 MATLAB 02: Array Creation

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

To start using Matlab, you only need be concerned with the command window for now.

Chapter 2. MATLAB Fundamentals

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

Objectives of this lesson

Matlab- Command Window Operations, Scalars and Arrays

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

EGR 102 Introduction to Engineering Modeling. Lab 05A Managing Data

Using the fprintf command to save output to a file.

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

ENGR 1181 MATLAB 09: For Loops 2

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

Lecture 2: Variables, Vectors and Matrices in MATLAB

Basics: vectors, matrices, arrays

Introduction to MATLAB for Engineers, Third Edition

ARRAY VARIABLES (ROW VECTORS)

How to learn MATLAB? Some predefined variables

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

An Introduction to MATLAB and the Control Systems toolbox Aravind Parchuri, Darren Hon and Albert Honein

Matrices 4: use of MATLAB

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Dr Richard Greenaway

Lecture 15 MATLAB II: Conditional Statements and Arrays

Introduction to MATLAB 7 for Engineers

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

CS 221 Lecture. Tuesday, 4 October There are 10 kinds of people in this world: those who know how to count in binary, and those who don t.

EE 301 Signals & Systems I MATLAB Tutorial with Questions

AN INTRODUCTION TO MATLAB

Introduction to MATLAB

ECE Lesson Plan - Class 1 Fall, 2001

MATLAB TUTORIAL WORKSHEET

TUTORIAL MATLAB OPTIMIZATION TOOLBOX

MATLAB Basics. Mohamed Taha. Communication Engineering Department Princess Sumaya University Page 1 of 32. Full Screen.

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

Introduction to Scientific Computing with Matlab

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

APPM 2460 Matlab Basics

Vector: A series of scalars contained in a column or row. Dimensions: How many rows and columns a vector or matrix has.

EGR 111 Introduction to MATLAB

A very brief Matlab introduction

Grace days can not be used for this assignment

2.0 MATLAB Fundamentals

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

Introduction to MATLAB

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK

Lecture 2. Arrays. 1 Introduction

Armstrong State University Engineering Studies MATLAB Marina 2D Arrays and Matrices Primer

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

PART 1 PROGRAMMING WITH MATHLAB

MATLAB QUICK START TUTORIAL

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MATLAB LAB 1

Excel Functions & Tables

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

CME 192: Introduction to Matlab

Performing Matrix Operations on the TI-83/84

University of Alberta

An Introduction to Numerical Methods

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

Chapter 1 Introduction to MATLAB

1 Introduction to Matlab

How to program with Matlab (PART 1/3)

I. Introduction to Programming Using MATLAB

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

MATLAB GUIDE UMD PHYS401 SPRING 2012

McTutorial: A MATLAB Tutorial

A Guide to Using Some Basic MATLAB Functions

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

ENGR 1181 MATLAB 05: Input and Output

MATLAB. Input/Output. CS101 lec

Scientific Computing with MATLAB

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Introduction to Matlab

An Introduction to MATLAB II

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans =

EOSC 352 MATLAB Review

Introduction to MATLAB Programming

Today s topics. Announcements/Reminders: Characters and strings Review of topics for Test 1

MATLAB Tutorial III Variables, Files, Advanced Plotting

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

INTRODUCTION TO MATLAB

Advanced Mathematical Methods for Civil Engineering Applications Wonsiri Punurai, PhD

Introduction to MATLAB

Introduction to Scientific Computing with Matlab

Matlab Programming Introduction 1 2

Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)

ME313 Homework #5. Matlab- Functions

Complex Dynamic Systems

Computer Programming

Scientific Computing Lecture Series Introduction to MATLAB Programming

A QUICK INTRODUCTION TO MATLAB

Transcription:

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 & twodimensional 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.

Array Creation In The Real World 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.

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

What is a vector? 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: [1 2 3 4] Row Vector: 1 Row by 4 Columns 1 2 3 4 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: 2 Rows 2 4 6 8 1 2 3 4 5 Rows 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 4 Columns 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: Jan Feb Mar Apr 10 10 9 8 Student A Attendance = 9 7 6 9 Student B 7 10 7 6 Student C

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 Image MATLAB 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 = [2 4 6 8 10]; % 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: [28 33 42 51] : >> x = [28; 33; 42; 51]; % With semi-colons Must use [ ] brackets. Elements can be separated by semi-colons OR using by an 'enter.

Basic Approach (for small arrays): Matrices The most basic approach for creating a matrix is combining row and column vector syntax. For example: >> mat = [ 1 2 3 4; 4 3 2 1; 5 6 7 8] Row 1 Row 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 = [2 4 6 8] Row vector of size [1 x 4] >> v2 = linspace(0, 10, 15) Column vector of size [15 x 1] >> v3 = [2 4 6 8 ; 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.