EGR 115 Introduction to Computing for Engineers

Slides:



Advertisements
Similar presentations
Multidimensional Array
Advertisements

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.
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.
Lecture 5 Input and Output inputfprintf © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
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
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.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© 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.
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.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing 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
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.
Introduction to Engineering MATLAB – 7 Script Files - 2 Agenda Script files continued.
EGR 115 Introduction to Computing for Engineers Formatted File Input / Output Wednesday 12 Nov 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 2: Sub-Arrays Friday 05 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.
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.
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.
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology Taxila.
Floating Point Representations
28 Formatted Output.
Chapter 9 - Formatted Input/Output
C Formatted Input/Output
ECE 1304 Introduction to Electrical and Computer Engineering
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to Matlab
Control Statements in Matlab
Lecture: MATLAB Chapter 1 Introduction
TMF1414 Introduction to Programming
EGR 115 Introduction to Computing for Engineers
Chapter 4 MATLAB Programming
MATLAB DENC 2533 ECADD LAB 9.
Lecture 2 Introduction to MATLAB
Chapter 9 - Formatted Input/Output
Computational Methods
Matlab Intro.
Islamic University of Gaza
Simulation And Modelling
CS 111 Introduction to Computing in Engineering and Science
Matlab Intro.
MatLab Program Used to Calculate Interactive
Introduction to Matlab
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Electrical and Computer Engineering Department SUNY – New Paltz
Chapter 5 JavaScript Numbers and Expressions
Presentation transcript:

EGR 115 Introduction to Computing for Engineers MATLAB Basics 2: Sub-Arrays Lecture 5 EGR 115 Introduction to Computing for Engineers

EGR 115 Introduction to Computing for Engineers Lecture Outline MATLAB Basics Sub-Arrays Displaying data Lecture 5 EGR 115 Introduction to Computing for Engineers

MATLAB basics Sub-arrays: A sub-array is a subset of a larger array >> a = [ 1 3 8 5 9 4]; The sub-array a(2:4) is the array [3 8 5] 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] i.e., elements a(1,2) and a(1,4) Since the array 2:2:5 is 2, 4 2:4 is the same as 2:1:4 What is the array a(1:3:9)? Answer: a(1), a(4), a(7) ERROR!!! Lecture 5 EGR 115 Introduction to Computing for Engineers

MATLAB basics Sub-arrays: Considering 2D arrays >> M = [ 1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15]; 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!! Lecture 5 EGR 115 Introduction to Computing for Engineers

MATLAB basics Sub-arrays: Some special predefined values pi  3.14159… 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 Machine dependent ans  stores the result of the last calculation Lecture 5 EGR 115 Introduction to Computing for Engineers

MATLAB basics Sub-arrays: Quiz 2.2 on page 44 of textbook c(2,:) c(:, end) c(1:2, 2:end) c(6) c(4:end) c(1:2, 2:4) c([1 3], 2) c([2 2], [3 3]) What is the size of each? Lecture 5 EGR 115 Introduction to Computing for Engineers

MATLAB basics Displaying Data: Display format Setting the Default Display Format -> Preferences Or type in command window >> format … format_examples.m Lecture 5 EGR 115 Introduction to Computing for Engineers

MATLAB basics Displaying Data: The “disp” and “fprint” functions Using the “disp” function >> disp(pi) >> disp(['The value of pi = ', num2str(pi)]) The “fprintf” function (borrowed from the C-language) Typical use: fprintf(format_spec, variable_list) 3.1416 Format (conversion char) Description %d Decimal notation %e Exponential notation %f Fixed-point notation %g More compact notation (%f or %e) \n New line Lecture 5 EGR 115 Introduction to Computing for Engineers

MATLAB basics Displaying Data: The “fprint” function 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 Field width is the min number of characters to be printed 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!! Lecture 5 EGR 115 Introduction to Computing for Engineers

EGR 115 Introduction to Computing for Engineers Next Lecture Data files, Array Operations, and Some of the built in functions Lecture 5 EGR 115 Introduction to Computing for Engineers