CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Introduction to MATLAB The language of Technical Computing.
Programming Paradigms and languages
Data Analytics and Dynamic Languages Lee E. Edlefsen, Ph.D. VP of Engineering 1.
Parallelizing Compilers Presented by Yiwei Zhang.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Introduction to a Programming Environment
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
Language Issues Misunderstimated? Sublimable? Hopefuller? "I know how hard it is for you to put food on your family.” "I know the human being and fish.
CS102 Introduction to Computer Programming
What is R By: Wase Siddiqui. Introduction R is a programming language which is used for statistical computing and graphics. “R is a language and environment.
A First Program Using C#
Antigone Engine Kevin Kassing – Period
5.3 Machine-Independent Compiler Features
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
CIS 601 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
You can make this in matlab!. Matlab Introduction and Matrices.
Introduction to M ATLAB EE 100 – EE Dept. - JUST.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Eng Advanced Marine Vehicles Todays agenda: Lab tomorrow at 2pm (structures lab) ‏ Advanced Marine Party Introduction to Matlab.
HTML, MATLAB & Delphi Aleksey Charapko 11/3/13. HTML Markup Language  Created at CERN for scientific purposes  No executable code  Controls the “look”
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Eng Ship Structures 1 Introduction to Matlab.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 2.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Sundermeyer MAR 550 Spring Laboratory in Oceanography: Data and Methods MAR550, Spring 2013 Miles A. Sundermeyer Introduction to Matlab ® Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Working with Arrays in MATLAB
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
MATLAB Tutorial EE313 Signals and Systems Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Jeff Andrews.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
A (VERY) SHORT INTRODUCTION TO MATLAB J.A. MARR George Mason University School of Physics, Astronomy and Computational Sciences.
Linear Algebra Libraries: BLAS, LAPACK, ScaLAPACK, PLASMA, MAGMA
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
Chapter 1: Introduction to Computers and Programming.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
Matlab.
Introduction to Matlab
Lecture: MATLAB Chapter 1 Introduction
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
(Mohammed Sami) Ashhab
Introduction to MATLAB
Part I – Matlab Basics.
Use of Mathematics using Technology (Maltlab)
Introduction To Programming Information Technology , 1’st Semester
Communication and Coding Theory Lab(CS491)
CSE 307 Basics of Image Processing
Matlab Basic Dr. Imtiaz Hussain
Simulation And Modeling
Introduction to Matlab
Laboratory in Oceanography: Data and Methods
Presentation transcript:

CIS 595 MATLAB First Impressions

MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages

MATLAB What Is MATLAB? MATLAB (MATrix LABoratory) high-performance language for technical computing computation, visualization, and programming in an easy-to- use environment Typical uses include: Math and computation Algorithm development Modelling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including Graphical User Interface building

MATLAB Matlab is an INTERPRETED language …with all the advantages and drawbacks ! …there is a Matlab Compiler, but it’s not worth too much in terms of speed Matlab takes care of the usual programming overhead, e.g. memory allocation, datatype conversion, parameters by value/reference … with all the advantages and drawbacks ! Matlab is NOT object oriented, although there are some attempts to extend it

MATLAB Matlab is able to cooperate with other languages, e.g. C, C++ JAVA Fortran

Why MATLAB A good choice for vision program development because: Easy to do very rapid prototyping Quick to learn, and well documented A good library of image processing functions Excellent display capabilities Widely used for teaching and research in universities and industry Another language to impress your boss with !

Why not MATLAB Has some drawbacks: Slow for some kinds of processes Not geared to the web Not designed for large-scale system development

MATLAB Components MATLAB consists of: The MATLAB language a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. The MATLAB working environment the set of tools and facilities that you work with as the MATLAB user or programmer, including tools for developing, managing, debugging, and profiling Handle Graphics the MATLAB graphics system. It includes high-level commands for two- dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. …(cont’d)

MATLAB Components … The MATLAB function library. a vast collection of computational algorithms ranging from elementary functions like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms as well as special image processing related functions The MATLAB Application Program Interface (API) a library that allows you to write C and Fortran programs that interact with MATLAB. It include facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files.

MATLAB Some facts for a first impression Everything in MATLAB is a matrix ! again: MATLAB is an interpreted language, no compilation needed (but possible) again: MATLAB does not need any variable declarations, no dimension statements, has no packaging, no storage allocation, no pointers Programs can be run step by step, with full access to all variables, functions etc.

What does Matlab code look like? A simple example: a = 1 while length(a) < 10 a = [0 a] + [a 0] end which prints out Pascal’s triangle: (with “a=” before each line).

What does Matlab code look like? Another simple example : t = 0:pi/100:2*pi; y = sin(t); plot(t,y)

What does Matlab code look like? Another simple example: t = 0:pi/100:2*pi; y = sin(t); plot(t,y) Remember: EVERYTHING IN MATLAB IS A MATRIX ! creates 1 x 200 Matrix Argument and result: 1 x 200 Matrix

Matrices !

Rows and columns are always numbered starting at 1 Matlab matrices are of various types to hold different kinds of data (usually floats or integers) A single number is really a 1 x 1 matrix in Matlab! Matlab variables are not given a type, and do not need to be declared Any matrix can be assigned to any variable

Matrices Building matrices with [ ]: A = [2 7 4] A = [2; 7; 4] A = [2 7 4; 3 8 9] B = [ A A ] ?

Matrices Building matrices with [ ]: A = [2 7 4] A = [2; 7; 4] A = [2 7 4; 3 8 9] B = [ A A ]

Matrices

Some operators must be handled with care: A = [1 2 ; 4 5] B = A * A prints B = A.* A prints Element by element multiplication

Submatrices A matrix can be indexed using another matrix, to produce a subset of its elements: a = [ ] b = [3 5 6] c = a(b):

Submatrices To get a subsection of a matrix, we can produce the index matrix with the colon operator: a(2:5) prints ans = This works in 2-D as well, e.g. c(2:3, 1:2) produces a 2 x 2 submatrix. The rows and columns of the submatrix are renumbered.

loops ‘for’ loops in MATLAB iterate over matrix elements: b = 0 for i = [ ] b = b + i; end Result:29 Note: The MATLAB way to write that program would have been: b = sum([ ]); Avoid loops if possible !

loops The typical ‘for’ loop looks like: for i = 1:6 … end Which is the same as: for i = [ ] … end

loops Once again: AVOID LOOPS

Avoiding loops How to avoid loops: Task: count the elements being greater than 5 in the following matrix M:

The non-MATLAB way: For rows=… { For columns=… { if M(rows,columns) > … inc counter } Avoiding loops

The MATLAB way: T = M > 5; Count = sum (T(:)) ; Or shorter: Count = sum(M(:) > 5); Avoiding loops

Another example, showing the mighty INDEXING possibilities : Task: eliminate the whitespaces in the following vector M Avoiding loops ABCDABCD

i = find (M ~= ‘ ‘); % result: i=[ ] M = M(i); Or shorter: M=M(find(M ~= ‘ ‘); Avoiding loops ABCDABCD