Outline Matlab tutorial How to start and exit Matlab Matlab basics.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/29/2003.
Guide To UNIX Using Linux Third Edition
Introduction to MATLAB MECH 300H Spring Starting of 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.
Extending MATLAB Write your own scripts and/or functions Scripts and functions are plain text files with extension.m (m-files) To execute commands contained.
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.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
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.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
Eng Ship Structures 1 Introduction to Matlab.
INTRODUCTION TO MATLAB LAB# 01
Khoros Yongqun He Dept. of Computer Science, Virginia Tech.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Basics of MATLAB By DR. Wafaa Shabana
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Digital Image Processing Introduction to M-function Programming.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Matlab Programming for Engineers
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to MATLAB
Release Numbers MATLAB is updated regularly
Computer Application in Engineering Design
Introduction to Mat lab
Matlab Training Session 4: Control, Flow and Functions
Basic operations in Matlab
Scripts & Functions Scripts and functions are contained in .m-files
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
MATLAB: Structures and File I/O
User Defined Functions
Introduction to MATLAB
StatLab Matlab Workshop
Matlab review Matlab is a numerical analysis system
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
MATLAB Tutorial Dr. David W. Graham.
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Lecture 2 Introduction to MATLAB
Digital Image Processing
Communication and Coding Theory Lab(CS491)
Vectors, matrices, and arithmetic
INTRODUCTION TO MATLAB
CSE 307 Basics of Image Processing
Introduction to MATLAB
Matlab Basic Dr. Imtiaz Hussain
Experiment No. (1) - an introduction to MATLAB
Using Script Files and Managing Data
Simulation And Modeling
Programming The ideal style of programming is Structured or
Presentation transcript:

Outline Matlab tutorial How to start and exit Matlab Matlab basics

Starting Matlab At this time, Matlab is only available on program1.cs.fsu.edu First you need to ssh to program1.cs.fsu.edu If you need to use the graphics and visualization tools in Matlab, make sure that X forwarding is enabled. You can do this by ssh –X program1.cs.fsu.edu Starting Matlab matlab & This starts the standard Matlab desktop as a background process September 19, 2018 CAP5415

Starting Matlab – cont. Help and documentation matlab –nodesktop This starts Maltab with a command line interface Help and documentation Matlab documentation site is available http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html In Matlab, you can get help help function-name to get help on a function doc function-name to get documentation on a function type function-name to show source code for a function Matlab is case sensitive so "a" and "A" are two different names. Comment statements are preceded by a “%” September 19, 2018 CAP5415

Command-Line Editing September 19, 2018 CAP5415

What is Matlab Matlab core is based on matrix and vector algebra; even scalars are treated as 1x1 matrices With an extended list of plotting and visualization tools Its functionality is also extended by toolboxes It provides an interactive environment (it is an interpreter language) for matrix operations It is also a programming/scripting language Many function names are similar to the standard C functions September 19, 2018 CAP5415

MATLAB Basics Definition of Variables Variables are assigned numerical values by typing the expression directly, for example: a = 1+2 yields: a = 3 The answer will not be displayed when a semicolon is put at the end of an expression, for example type a = 1+2; When a variable that has defined is used, Matlab creates a new variable Predefined variables which can be used at any time: September 19, 2018 CAP5415

Definition of Matrices Lets creates a 1x4 vector with elements 1, 3, 5 and 7 v = [1 3 5 7]; twoXthree= [1 2 4; 3 6 8]; [M,N] = size(twoXthree) returns the number of rows (2) and columns (3) in separate output variables. Lets creates the matrices: t = 0:10; x = cos(t*pi); x with elements equal to cos(t*pi) for t = 0, 1,..., 10. X [cos(0) cos(pi) cos(2*pi)…..cos(10*pi)] September 19, 2018 CAP5415

Arithmetic Operators September 19, 2018 CAP5415

Logical and Relational Operators Logical operations &, &&, |, ||, ~, and xor Relational operators ==, ~=, <, <=, >=, > Logical functions Any, all, isnan, isinf, isfinite, isempty, isequal September 19, 2018 CAP5415

Accessing Matrices The element in row i and column j of A is denoted by A(i,j) Using the colon (:) operator, one can refer more than one element in a matrix September 19, 2018 CAP5415

Advanced Data Structures You can have multi-dimensional arrays (more than 2 dimensions) You can define a cell structure to hold elements of different sizes using cell You can also have data structures by using struct September 19, 2018 CAP5415

Advanced Data Structures September 19, 2018 CAP5415

Plotting Commands covered: plot, xlabel, ylabel, title grid, axis, stem, subplot xlabel('time (sec)'); ylabel('step response'); title('My Plot'); To plot more than one graph on the screen, use the command subplot(mnp) which partitions the screen into an mxn grid where p determines the position of the particular graph counting the upper left corner as p=1. For example, subplot(211),semilogx(w,magdb); subplot(212),semilogx(w,phase); September 19, 2018 CAP5415

3D - Plotting example x=[0:10]; y=[0:10]; z=x’*y; mesh(x,y,z); title(‘3-D Graph’); September 19, 2018 CAP5415

Loading and Saving Data When using MATLAB, you may wish to leave the program but save the vectors and matrices you have defined. To save the file to the working directory, type save filename where "filename" is a name of your choice. To retrieve the data later, type load “filename” September 19, 2018 CAP5415

M-files M-files are macros of MATLAB commands that are stored as ordinary text files with the extension "m", that is filename.m example of an M-file that defines a function, create a file in your working directory named yplusx.m that contains the following commands: Write this file: function z = yplusx(y,x) z = y + x; -save the above file(2lines) as yplusx.m x = 2; y = 3; z = yplusx(y,x)  5 Get input by prompting on m-file: T = input('Input the value of T: ') September 19, 2018 CAP5415

M-files – cont. There are two kinds of M files Scripting Function It consists a list of commands and statements that will be executed in order Function It defines one or more functions that can be called In Matlab, a function is similar to a C function There are different kinds of Matlab functions Anonymous functions, which do not require a .m file but only a single Matlab expression Primary and subfunctions September 19, 2018 CAP5415

M-files – cont. Primary functions Nested functions Primary functions are required to define a primary function A number of subfunctions can be defined in the same file Primary functions can be invoked from anywhere while subfunctions can only be invoked within the corresponding primary function Nested functions Defined with the body of a Matlab function September 19, 2018 CAP5415

M-files – cont. Global variables You can define global variables that can be accessed from different functions by using global in all the functions Each function takes a number of input arguments and a number of output arguments The eval function It is a power text macro facility which uses the Matlab interpreter to evaluate the expression September 19, 2018 CAP5415

M-files – cont. Function handles There are also function functions You reference a function though a function handle There are also function functions That is, one function works on another function September 19, 2018 CAP5415

Flow Control Matlab provides several flow control constructs “if” “switch and case” “for” “while” “continue” “break” “try – catch” “return” September 19, 2018 CAP5415

Flow Control If Switch and case September 19, 2018 CAP5415

Flow Control For while September 19, 2018 CAP5415

Flow Control Try and catch September 19, 2018 CAP5415

File Operations in Matlab Similar to C standard functions Reading from a file First you need to open a file using fopen Then you can read from the file using fscanf and fread Writing to a file Then you can write to a file using fprintf and fwrite After you are done with a file, use fclose to close the file September 19, 2018 CAP5415

File Operations in Matlab Example Readp5 to read an image in pgm format September 19, 2018 CAP5415

Readp5.m with Error Checking September 19, 2018 CAP5415

Advanced Matlab Features Visualization in Matlab becomes sophisticated September 19, 2018 CAP5415

3-D Visualization September 19, 2018 CAP5415

Advanced Features Matlab compilers There are also Matlab compilers which can generate C/C++ or programs automatically from your .m Matlab programs You can also mix Matlab with C/C++ programs or programs in other programming language in two ways Through mex compiler Through a Matlab engine and a library September 19, 2018 CAP5415

3-D Visualization September 19, 2018 CAP5415

GUIDE Matlab also provides a graphical user interface development environment for creating graphical user interfaces Layout editor GUIDE automatically generates an M-file that controls how the GUI operates September 19, 2018 CAP5415

Debugging Keyboard statement stops a Matlab function and allows one to interactively check variables You can also set breakpoints and so on if you use the Matlab editor September 19, 2018 CAP5415

Ways to Make Matlab Run Faster Vectorization Preallocation September 19, 2018 CAP5415