MATLAB (Lecture 2) BY:MAHA ALMOUSA.

Slides:



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

A number of MATLAB statements that allow us to control the order in which statements are executed in a program. There are two broad categories of control.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Programming with MATLAB
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
MATLAB Basics CS 111 Introduction to Computing in Engineering and Science.
MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
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.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting.
Fall 2006AE6382 Design Computing1 Control Statements in Matlab Topics IF statement and Logical Operators Switch-Case Disp() vs fprintf() Input() Statement.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
MATLAB Technical Computing Environment. MATLAB Matlab is an interactive computing environment that enables numerical computation and data visualization.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
CSE123 Lecture 3 Files and File ManagementScripts.
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.
Digital Image Processing Introduction to M-function Programming.
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.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
INTRODUCTION TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in.
Matlab Programming for Engineers
ECE 1304 Introduction to Electrical and Computer Engineering
EEE 161 Applied Electromagnetics
Control Statements in Matlab
Computing Fundamentals
Chapter 3 Arrays and Vectors
2.5 Another Java Application: Adding Integers
Programming with MATLAB
Scripts & Functions Scripts and functions are contained in .m-files
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
MATLAB: Structures and File I/O
Conditional Statements
Matlab review Matlab is a numerical analysis system
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
CS100J 26 April. Matlab Use help button!!! Variables, values, types
Use of Mathematics using Technology (Maltlab)
MATLAB Basics.
Lecture 2 Introduction to MATLAB
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
Introduction to Matlab
INTRODUCTION TO MATLAB
Note on Indexing of Array Elements
Islamic University of Gaza
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
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.
244-2: MATLAB/Simulink FUNDAMENTALS
Using Script Files and Managing Data
CS 111 Introduction to Computing in Engineering and Science
Matlab Basics.
Introduction to C Programming
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

MATLAB (Lecture 2) BY:MAHA ALMOUSA

Some Basic Commands who lists all of the variables in your matlab workspace clc Clears the command window whos list the variables and describes their matrix size clear erases variables and functions from memory Clear x erases the matrix 'x' from your workspace ; (semicolon) prevent commands from outputting results % (percent sign) comments line … A line can be terminated with three periods (...), which causes the next line to be a continuation line

The Colon Operator For example: 1:10 is a row vector containing the integers from 1 to 10: 1 2 3 4 5 6 7 8 9 10 To obtain non-unit spacing, specify an increment. For example: 100:-7:50 will give you 100 93 86 79 72 65 58 51

Input Function The input function displays a prompt string in the Command Window and then waits for the user to respond. my_val = input( ‘Enter an input value: ’ ); displays prompt as a prompt on the screen, waits for input from the keyboard, and returns the value entered in my_val. in1 = input( ‘Enter data: ’ ); in2 = input( ‘Enter data: ’ ,`s`); returns the entered string as a text variable rather than as a variable name or numerical value.

disp The disp( array ) function >> disp( 'Hello' ) Hello 5 >> disp( [ 'Bilkent ' 'University' ] ) Bilkent University >> name = 'Alper'; >> disp( [ 'Hello ' name ] ) Hello Alper

The ‘Fprintf’ function The fprintf( format, data ) function %d integer %f floating point format %e exponential format %g either floating point or exponential format, whichever is shorter \n new line character \t tab character

>> fprintf( 'Result is %d', 3 ) >> fprintf( 'Area of a circle with radius %d is %f', 3, pi*3^2 ) Area of a circle with radius 3 is 28.274334 >> x = 5; >> fprintf( 'x = %3d', x ) x = 5 >> x = pi; >> fprintf( 'x = %0.2f', x ) x = 3.14 >> fprintf( 'x = %6.2f', x ) x = 3.14 >> fprintf( 'x = %d\ny = %d\n', 3, 13 ) x = 3 y = 13

The ‘feval(..,..)’ function

Function with One Output M-file function that returns a single result Define a function in a file named average.m that accepts an input vector, calculates the average of the values, and returns a single result.

Function with multiple outputs Define a function in a file named stat Function with multiple outputs Define a function in a file named stat.m that returns the mean and standard deviation of an input vector.

Relational operations

Results of comparison using relational operators: ZERO, if comparison is false. False = 0 ONE, if comparison if true. True = 1 If comparing numbers, any non-zero is considered “true”

Example >> x=2; >> y=3; >> z=x<y; % same as z = (x<y) >> u=x==y; % same as u = (x==y) >> z,u z = 1 u =

The difference between ‘=‘ and ‘==‘

Logical operations xor (exclusive OR) ~ (NOT): z = ~x. & (AND): used to link logical expressions: z =(x<y) & (a>b). | (OR): q =(x<y) | (a>b). && (Short-Circuit AND): used for operations on 2 scalar logical expressions. || (Short-Circuit OR): (Note | is the shift-\ key, above Enter). xor (exclusive OR) is used to link logical expressions: w = xor(A, B).

Example

If statements If logical expression statements end

Example If a <= 30 total = 2*a end

If-else statements If logical expression statement group 1 else end

Example If a <= 30 total = 2*a else total = a + 10 end

If-elseif-else If logical expression 1 statement group 1 end

Example If a <= 30 c = a * 2 elseif c >= 20 d = c else d = 0 end

For loops for loop variable = m:s:n statements end

Example

Assighnment Create an M-file Function that uses if and while statements.