EGR 115 Introduction to Computing for Engineers MATLAB Basics 2: Sub-Arrays Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers.

Slides:



Advertisements
Similar presentations
Multidimensional Array
Advertisements

MATLAB Examples. CS 1112 MATLAB Examples Find the number of positive numbers in a vector x = input( 'Enter a vector: ' ); count = 0; for ii = 1:length(x),
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
Lecture 8 Logical Operations Logical functions & Relational operators © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
MATLAB Basics CS 111 Introduction to Computing in Engineering and Science.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB 7 for Engineers
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
Introduction to MATLAB
EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays.
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 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Fall 2006AE6382 Design Computing1 Control Statements in Matlab Topics IF statement and Logical Operators Switch-Case Disp() vs fprintf() Input() Statement.
MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
1 Yangon Technological University Department of Mechanical Engineering Computer Application In Mechanical Engineering I ME Dr. Yin Yin Tun Deputy.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 5 JavaScript.
Engineering Analysis – Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Introduction to Engineering MATLAB – 7 Script Files - 2 Agenda Script files continued.
1 CS1371 Introduction to Computing for Engineers Introduction to Matlab.
EGR 115 Introduction to Computing for Engineers Formatted File Input / Output Wednesday 12 Nov 2014 EGR 115 Introduction to Computing for Engineers.
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.
EGR 115 Introduction to Computing for Engineers Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
1 CS1371 Introduction to Computing for Engineers Control Statements 9/4/2003.
Matlab Data types, input and output. Data types Char: >> a = ‘ Jim ’ Char: >> a = ‘ Jim ’ Numeric: uint8, uint16, uint32, uint64 int8, int16, int32, int64.
Fall 2006AE6382 Design Computing1 Control Statements in Matlab Topics IF statement and Logical Operators Switch-Case Disp() vs fprintf() Input() Statement.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 5: Applications – Vector Math Friday 12 Sept 2014 EGR 115 Introduction to Computing for Engineers.
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.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
CS 1704 Introduction to Data Structures and Software Engineering.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 3 Friday 17 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Project Teams Project on Diffusion will be a TEAM project. 34 Students in class so 6 teams of 5 and one Team of 4. Determine members of team and a team.
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology Taxila.
An Introduction to Programming in Matlab Emily Blumenthal
Introduction to Matlab
EGR 115 Introduction to Computing for Engineers
Control Statements in Matlab
Lecture: MATLAB Chapter 1 Introduction
EGR 115 Introduction to Computing for Engineers
Problem Solving with MATLAB
Lecture 2 Introduction to MATLAB
CS 111 Introduction to Computing in Engineering and Science
Presentation transcript:

EGR 115 Introduction to Computing for Engineers MATLAB Basics 2: Sub-Arrays Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers

Lecture Outline Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers MATLAB Basics  Sub-Arrays  Displaying data Slide 2 of 10

MATLAB basics Sub-arrays: Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers A sub-array is a subset of a larger array >> a = [ ];  The sub-array a(2:4) is the array [2 8 5] o i.e., elements a(1,2), a(1,3), and a(1,4) – Or elements a(2), a(3), and a(4)  The sub-array a(2:2:5) is the array [3 5] o i.e., elements a(1,2) and a(1,4) – Since the array 2:2:5 is 2, 4 Answer: a(1), a(4), a(7) ERROR!!! What is the array a(1:3:9)? Slide 3 of 10

MATLAB basics Sub-arrays: Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers Considering 2D arrays >> M = [ ; ; ];  The sub-array M(:,3:5) corresponds to all rows and cols 3, 4, 5  We can also index from the “end” >> M(:,end) refers to the last column  We can reassign a sub-set of the array >> M(1:2, [3 4]) = zeros(2,2); An error will occur if the LHS & RHS sizes are different!! Slide 4 of 10

MATLAB basics Sub-arrays: Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers Some special predefined values  pi – … to 15 significant digits  1i – The square root of -1 i.e., an imaginary number  Inf – Result of dividing by zero, i.e. infinity  NaN – Not-a-Number (undefined result)  clock – date & time = [year, month, date, hr, min, sec.sec]  eps – smallest possible number in MATLAB o Machine dependent  ans – stores the result of the last calculation Slide 5 of 10

MATLAB basics Sub-arrays: Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers Quiz 2.2 on page 43 of textbook a)c(2,:) b)c(:, end) c)c(1:2, 2:end) d)c(6) e)c(4:end) f)c(1:2, 2:4) g)c([1 3], 2) h)c([2 2], [3 3]) Slide 6 of 10

MATLAB basics Displaying Data: Display format Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers Setting the Default Display Format -> Preferences  Or type in command window >> format … format_examples.m Slide 7 of 10

MATLAB basics Displaying Data: The “disp” and “fprint” functions Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers Using the “disp” function >> disp(pi) >> disp(['The value of pi = ', num2str(pi)]) The “fprintf” function (borrowed from the C-language)fprintf  Typical use: fprintf(format_spec, variable_list) Format (conversion char) Description %dDecimal notation %eExponential notation %fFixed-point notation %gMore compact notation (%f or %e) \nNew line Slide 8 of 10 Concatenate the strings

MATLAB basics Displaying Data: The “fprint” function Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers fprintf examples:  Compare effects of the various conversion chars >> fprintf('Compare: pi = %d pi = %e pi = %f pi = %g\n', pi, pi, pi, pi);  We can also control the field width and precision o Field width is the min number of total digits to be printed o Precision is the number of decimal places >> fprintf('Compare: pi = %5.0f pi = %5.3f pi %5.8f \n', pi, pi, pi); fprintf in MATLAB is NOT exactly the same as the original C-function!! Slide 9 of 10

Next Lecture Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers Data files, Array Operations, and Some of the built in functions Slide 10 of 10