CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.

Slides:



Advertisements
Similar presentations
Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Advertisements

Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
1 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Introduction to MATLAB
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
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.
Matlab intro The Environment
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB Fundamentals.
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.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
How to Use MATLAB A Brief Introduction. 2 What can MATLAB do? Matrix Operations Symbolic Computations Simulations Programming 2D/3D Visualization.
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.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
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.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Let’s stay fresh with C. What does this print? void mystery(int * x); main(){ int a = 5; mystery(&a); printf("%d\n",a); } void mystery(int * x){ int y;
An Introduction to Programming in Matlab Emily Blumenthal
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.
ECE 1304 Introduction to Electrical and Computer Engineering
Lecture 25: Exploring data
Two-Dimensional Plots
Matrices and Arrays.
MATH 493 Introduction to MATLAB
Vectors and Matrices I.
Introduction to Matlab
INTRODUCTION TO MATLAB
Plotting Signals in MATLAB
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Presentation transcript:

CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting

CS100A, Fall 1998, Lecture 192 Arrays (review) All data in Matlab is actually an array (or a vector) — a 1- or 2-dimensional table of numbers. A single value, called a scalar, is simply an array of size 1. To construct a 1-D array, list its elements surrounded by square brackets. y = [ ] Individual elements are accessed using a parenthesized subscript. x(3) The first element of array x is x(1). The number of elements in array x is given by the built-in function length(x)

CS100A, Fall 1998, Lecture 193 Creating Arrays (review) An array of evenly-spaced values can be generated by linspace(minVal, maxVal, nVals) Two arrays can be combined with a comma and brackets: x = [1 2 3]; y = [4 5 6]; [x, y](is [ ]) z = [x, [x, y]];

CS100A, Fall 1998, Lecture 194 Creating Arrays (colon) The colon can be used to generate a sequence of values. Forms: lowValue : highValue lowValue : step : highValue Examples: 1 : 10 1 : 2 : 10 1 : 0.5 : : –1 : 1 0 : 0.01 : 0.5 A sequence of values is an array value. a = 0 : 2 : 16 b = [1 : 6] / 3 A sequence of integers can also be used to select a segment of an array. a(3:6)

CS100A, Fall 1998, Lecture 195 Array Functions There are many functions to compute facts about arrays. min(x), max(x), mean(x),... Array Operations Basic operations on arrays are performed element-by-element. Example: function applications: x = [ ] floor(x) An operation may involve an array and a scalar. The operation is performed on each element of the array and the result is an array of these values. x / 2

CS100A, Fall 1998, Lecture 196 Array Operations (cont.) Operations may combine two arrays if they have exactly the same length. x = [ ] y = [ ] x + y y - x The operations + and – work as expected. For element-by-element multiplication, division, and exponentiation, use.*,./, and.^. (Explanation: The usual operators *, /, and ^ perform matrix [Linear algebra] operations between arrays. We will not cover that in CS100.)

CS100A, Fall 1998, Lecture 197 Multiple Subscripts In general, an array of integers can be used as a subscript. The result is an array consisting of the elements selected by the subscripts in the order given. a = 10 * [0:9] a([3 4 5]) a(3:5) a([5 4 3]) a([ ]) a(10:-1:1)

CS100A, Fall 1998, Lecture 198 Logical Operations & Arrays — 0/1 Arrays Logical operations yield 0 (false) or 1 (true). When performed on arrays, an array of 0’s and 1’s is the result. a = [ ] b = [ ] a > b a ~= b a > 5 rem(a, 3) rem(a, 3) == 0 The functions any and all yield 1 if, respectively, any or all of the elements in their array argument are non-zero.

CS100A, Fall 1998, Lecture 199 Selecting Elements with 0/1 Arrays If a vector of 0’s and 1’s is used as a subscript of an array of the same length, the result is a new array containing only those elements of the old array with a 1 subscript. This is especially useful when the result of a logical expression is used as a subscript to select array elements based on some condition. a = [ ] a([ ]) b = a - 10 b > 0 b( b > 0 ) a( rem(a,3) ~= 0 )

CS100A, Fall 1998, Lecture 1910 Managing the Work Session clc Clears the Command window clear Removes variables from memory help name Searches online help for the topic name lookfor nameSearches the help entries for the specified keyword name quitStops Matlab whoLists the variables currently in memory whosLists the current variables and sizes, and indicates whether they have imaginary parts

CS100A, Fall 1998, Lecture 1911 Basic Plotting If x and y are two arrays with the same number of elements, plot(x,y) draws a plot of x (horizontal) vs y (vertical) x = linspace(0, 4*pi, 250); y = sin(x); plot(x,y) Normally the graph is scaled so the full range of x and y values fill the plot. To have equal spacing on the axes, enter axis(‘equal’) after the plot has been drawn (using straight quote marks). You can label the axes and title the graph after it has been drawn: xlabel(‘x axis label’) ylabel(‘y axis label’) title(‘A Fabulous Graph’)

CS100A, Fall 1998, Lecture 1912 Plot Options The plot command has an optional third argument that can be used to specify the line color and style. Examples: v = -10:0.5:10; fv = 3*pi*sin(v).^2 - v; plot(v, fv, ‘g’); % green line plot(v, fv, ‘b:’); % blue dotted line plot(v, fv, ‘r+’); % red crosses plot(v, fv, ‘c--’); % cyan dashed line Use help plot to find other possibilities

CS100A, Fall 1998, Lecture 1913 Multiple Plots Normally each new plot is drawn in a blank window, replacing whatever is there. Use hold on to retain the previous plot so you can draw a new one over it. Use hold off to release the previous plot so the next one will appear in a blank window. Example: x = linspace(0, 6*pi, 1000); y = sin(x); z = cos(x); plot(x, y, ‘r’); hold on plot(x, z, ‘g’);