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.
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.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
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.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
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.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
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.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
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.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
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 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
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 Structured Programming EEN170 Programming in MATLAB.
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
Yanal Alahmad Java Workshop Yanal Alahmad
2.5 Another Java Application: Adding Integers
Other Kinds of Arrays Chapter 11
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Conditional Statements
Matlab review Matlab is a numerical analysis system
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
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
Introduction to Matlab
CS 111 Introduction to Computing in Engineering and Science
Matlab Basics.
Introduction to C Programming
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
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: ’ ); in1 = input( ‘Enter data: ’ ); in2 = input( ‘Enter data: ’ ,`s`);

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 Creat m-file function to find factorial of x (use f statement if x<0)