ENG 1181 1 College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.

Slides:



Advertisements
Similar presentations
ENG004 ALGORITHMS & INT. TO PROGRAMMING Week 3 “An introduction to arrays and matrices” Ahmet Anıl Dindar
Advertisements

Maths for Computer Graphics
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
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.
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.
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.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Chapter 9 Above: An early computer input/output device on the IBM 7030 (STRETCH)
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
AN ENGINEER’S GUIDE TO MATLAB
Matlab tutorial course Lesson 2: Arrays and data types
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.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
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.
Computer Science: A Structured Programming Approach Using C1 2-7 Input/Output Although our programs have implicitly shown how to print messages, we have.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Working with Arrays in MATLAB
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
ENG 1181 College of Engineering Engineering Education Innovation Center P. 1 MAT - Conditional Statements Topics Covered: 1. if based conditional statements.
>> 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.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
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.
ENG College of Engineering Engineering Education Innovation Center 1 Basic For Loops in MATLAB Programming in MATLAB / Chapter 6 Topics Covered:
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.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
ENG 1181 College of Engineering Engineering Education Innovation Center 1 Script File Input – Output : Chapter 4 PLEASE HAVE STUDENTS START MATLAB NOW.
Matlab Basic. MATLAB Product Family 2 3 Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit.
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.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 2 in MATLAB Topics Covered: 1.More about 2-D plots  Placing multiple.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CMPS 1371 Introduction to Computing for Engineers VECTORS.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
ENG College of Engineering Engineering Education Innovation Center 1 Functions 2 in MATLAB Topics Covered: 1.Functions in Script Files Inline Functions.
ENG College of Engineering Engineering Education Innovation Center 1 Array Operations in MATLAB 1.Types of Matrix arithmetic 2.Dot operators Mathematical.
Chapter 4 Section 1 Organizing Data into Matrices.
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
Manipulating MATLAB Matrices Chapter 4
EGR 115 Introduction to Computing for Engineers
Other Kinds of Arrays Chapter 11
Communication and Coding Theory Lab(CS491)
Using Script Files and Managing Data
Working with Arrays in MATLAB
Computer Simulation Lab
Presentation transcript:

ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2. Character arrays. Creating Arrays / Chapter 2

ENG ARRAY ADDRESSING (VECTOR) The address of an element in a vector is its position in the row (or column), starting at 1. >> v = [ ] v = >> v(4) ans = 23 >> v(7) ans = 81 >> v(1) ans = 35 It is possible to change an element in a vector by entering a value to a specific address directly: >> v(6) = 273 v =

ENG Addressing Specified Elements of a Vector Any combination of elements from a vector can be addressed in any order >> v = [ ] v = >> u = v([ ]) u = v([ ]) is the same as ( [v(4), v(5), v(7), v(3), v(3)] ).

ENG USING A COLON (:) WHEN ADDRESSING VECTORS The colon operator can be used to generate a list of elements to address All the elements of a vector (either a row vector or a column vector) Elements 3 through 7 ( [v(3), v(4), v(5), v(6), v(7)] ). >> v = [ ] v = >> u = v(3:7) u = v(:) v(3 : 7)

ENG ARRAY ADDRESSING (MATRIX) >> m=[ ; ; ] m = >> m(1,1) ans = 3 >> m(2,3) ans = Single elements can be used like variables in computations: >> m(2,3) - m(1,1) ans = 7

ENG USING A COLON (:) WHEN ADDRESSING MATRICES A(:, 3) A(2, :) A(:, 2:5) A(2:4, :) A(1:3, 2:4) A([4 2],:) Elements in all the rows of column 3 Elements in all the columns of row 2 Elements in columns 2 through 5 in all the rows Elements in rows 2 through 4 in all the columns Elements in rows 1 through 3 and in columns 2 through 4 Elements in all the columns of rows 4 then 2

ENG ADDRESSING MATRICES >> A = [ ; ; ; ; ] A = >> B = A(:,3) B = >> C = A(2,:) C = Define a matrix Define a matrix using part of A

ENG ADDRESSING MATRICES >> D = A(:, 2:5) D = >> F = A(1:3,2:4) F = >> E = A(2:4,:) E = A = >> G = A([5 2],5:-2:1) G =

ENG ADDRESSING MATRICES >> A(1:2,1:3) = B([5 5],2:4) A = >> A = zeros (4,5) A = B = >> A(3:4,[1 4 5]) = B(1:2,1:3) A =

ENG  Strings are a special case of a vector (row array) where every element is a character.  Strings are created by entering the characters between single quotes.  String arrays can include letters, digits, other symbols, and spaces  Examples of strings: 'ad ef ', '3%fr2', '{edcba :21!' Character Arrays

ENG STRING VARIABLES >> a = 'ERty 8' a = ERty 8 >> B = ['My name is John Smith'] B = My name is John Smith a has 6 elements, and B has 21 elements The elements can be addressed like any other row array >> a(4) ans = y >> B(12) ans = J

ENG STRING VARIABLES >> x = 536 x = 536 >> x = '536' x = 536 The string variable: is not the same as the number variable: If you use a string variable in calculations, you get an answer based on the ascii storage code for those characters (probably not what you wanted)! An important application of strings is in creating input prompts and output messages. This will be shown later when script file I/O (input/output) is discussed