MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

Lecture 5.
Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Process simulation, optimisation and design. P.S.O.D. ORGANIZATION ISSUES.
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
Introduction to Matlab Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Digital Image Processing Lecture3: Introduction to MATLAB.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
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.
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Eng Ship Structures 1 Introduction to Matlab.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
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.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
MA/CS 375 Fall 2002 Lecture 3. Example 2 A is a matrix with 3 rows and 2 columns.
Feb. 8, 2008 UHCO Graduate Course in MATLAB Core Programming Module Best Practices Core Grant Programming Module Best Practices (Coding Conventions) General.
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.
A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
A (VERY) SHORT INTRODUCTION TO MATLAB J.A. MARR George Mason University School of Physics, Astronomy and Computational Sciences.
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
ECE 1304 Introduction to Electrical and Computer Engineering
Computer Application in Engineering Design
Matlab Training Session 4: Control, Flow and Functions
L – Modeling and Simulating Social Systems with MATLAB
Lecture: MATLAB Chapter 1 Introduction
Scripts & Functions Scripts and functions are contained in .m-files
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
User Defined Functions
Introduction to MATLAB
Matlab review Matlab is a numerical analysis system
Use of Mathematics using Technology (Maltlab)
Communication and Coding Theory Lab(CS491)
Introduction to Matlab
CSE 307 Basics of Image Processing
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.
Experiment No. (1) - an introduction to MATLAB
Simulation And Modeling
Presentation transcript:

MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course

2 Purpose of the lecture This lecture contains a short introduction to the MATLAB –For further details see other sources Later we will apply Matlab to a simple simulation exercise of a communication system In that exercise we study, at the same time as learning MATLAB, different aspects of communication simulations

3 MATLAB MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation and visualization You can solve complex numerical problems in a fraction of the time required with a programming language such as Fortran or C. The name MATLAB is derived from MATrix LABoratory

4 MATLAB … MATLAB is an expression language –the expressions you type are interpreted and evaluated MATLAB statements are usually of the form –variable = expression, or simply –expression

5 MATLAB … MATLAB contains several build-in functions –Written either using C, or as a form of m-files You can create your own functions (m-files) –Most of work is writing functions that are used to execute simulations You can obtain functions (m-files) written by others BUT, AS ALWAYS, –Remember to validate all the functions (if not already validated by others) –Even build-in functions may contain errors, or are not usable in your problem since every numeric algorithm has its limitations remember to check the function manual

6 MATLAB … MATLAB has its core with some basic functions (which can be used to build everything) In addition, it has TOOLBOXes that include build- in functions to support different areas or multiple of areas TOOLBOXes ease and fasten simulations in their areas –Naturally, one has to learn how to use functions in TOOLBOXes

7 Toolboxes

8

9 Information sources Matlab primer – –Guide to basic properties, –very helpful if read and executed simultaneously Mathworks home page – –Information of all Matlab related products –Helps –User created m-files from several areas

10 Matrices MATLAB can efficiently use matrices and vectors –MATLAB handles vector  vector and matrix  vector products faster than for loops (if sizes are not too large) –Many books and papers where you can find algorithms use matrix notation –So, learn to use matrices and vectors efficiently! –A hint: always write vectors in the same way Either as a column or row vector Column form is the most common

11 M-files You can call m-files in the command line or inside m-files –You can use other m-files in your simulations A good practice is to make small, general-usable m-files (if possible) and then apply them in your master simulation m-file –The generality allows you to apply the same m-file in many places Build-in m-files are general M-files are called such since they have file type “.m”

12 M-files M-files can be either script files or function files A script file consists of a sequence of normal MATLAB statements When the m-file is called, the statements are executed Variables in a script file are global and will change the value of variables of the same name in the environment of the current MATLAB session

13 Script file example We want to calculate logarithm (base 10) of 10 In command line it is log10(10) (since log is ln) Put this as a variable a=log10(10) Create m-file which calculates logarithm on 100, and puts the result in a variable a, name this as testA.m Execute first a=log10(10) and then testA.m

14 Value of variable a changes since script files have global variables If the result is not a named variable Matlab gives ans

15 M-files … Function files provide extensibility to MATLAB You can create new functions specific to your problem which will then have the same status as other MATLAB functions Variables in a function file are by default local –A variable can, however, be declared global (see help global) –Locality means that a value of variable on the command line is not changed even if a function file contains the same variable

16 M-files … Inputs to function files may be variables Remember to comment your files –you may even create a help part that explains what the function does –Commenting helps you and others to remember what the different lines do and what for the different variables are

17 Function file example We create a function file that –computes a sinusoidal function with a frequency f over an interval 0 - T –results values of a sinusoidal and the interval –And plots the signal In addition –We make a help –and comment the file

18 function [y,t]=testB(f,T,n); %[y,t]=testB(f,T,n) plots a sinusoidal with a frequency f [Hz] %over an interval 0 - T [s] and results values of the function y and %corresponding time instants. n+1 is the number of time instants, %the default being 128. % %by Michael Mfilewriter, 2006 %check if n is given or not %if not set it as default if nargin<3, n=127; else n=n-1; %makes sure that we have n+1 time instants end

19 %create time scale with n steps t=0:T/n:T; t=t(:); % t(:) makes a column vector %compute values of sinusoideal y=sin(2*pi*f*t); %plot it with t as a x-axis and y as a y-axis plot(t,y) xlabel('time [s]') %creates text for x-label ylabel('sinusoidal') %creates text for y-label

20 [y,t]=testB(1,10,1024); results

21 Help If m-files have a help it is called as help m-file E.g., if we call help of testB.m as help testB It results [y,t]=testB(f,T,n) plots a sinusoidal with a frequency f [Hz] over an interval 0 - T [s] and results values of the function y and corresponding time instants. n+1 is the number of time instants, the default being 128. by Michael Mfilewriter, 2006 That is, help results everything commented (by %) in the code before first line without %