A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.

Slides:



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

P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen.
Flow Charts, Loop Structures
Programming with MATLAB
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
MATLAB Basics CS 111 Introduction to Computing in Engineering and Science.
Programming in Matlab Day 1: Basics. Matlab as a calculator >> 2+2 ans = 4 >> 2^3 ans = 8 >> sqrt(2) ans = Command Window Basic operations Sum:
Introduction to MATLAB
Introduction to Matlab Jianguo Wang CSSCR September 2009.
MATLAB FUNDAMENTALS: INPUT/OUTPUT LOGIC CONTROL STRUCTURES HP 101 – MATLAB Wednesday, 9/24/2014
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
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.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
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.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
MATLAB FUNDAMENTALS: CONTROL STRUCTURES – LOOPS HP 100 – MATLAB Wednesday, 10/1/2014
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
INTRODUCTION TO MATLAB LAB# 01
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
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.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
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.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Introduction to Matlab
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Matlab Training Session 4: Control, Flow and Functions
MATLAB DENC 2533 ECADD LAB 9.
Matlab review Matlab is a numerical analysis system
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
CS100J 26 April. Matlab Use help button!!! Variables, values, types
MATLAB Basics.
INTRODUCTION TO MATLAB
Matlab.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
CS 111 Introduction to Computing in Engineering and Science
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Programming The ideal style of programming is Structured or
Presentation transcript:

A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2

Clearing theWorkspace Matlab keeps all the variables you declare in memory until you tell it to erase them. InMatlab lingo, the place where user-defined variables are stored is referred to as the workspace. To erase a single variable from the workspace, type clear and then the variable name. clear x If you want to erase all variables in the workspace, simply type clear

MATLAB fundamentals

MATLAB as a Calculator You can use Matlab as a calculator by typing commands at >>, like these. Try them out *3 5/6 Sin(5) to enter numbers like 1.23e15

Variables Variables are not declared before they are used. The assignment command in Matlab is simply the equal sign. Note that variable names in Matlab are case sensitive. All Variables are arrays(A collection of data values organized into rows and columns)

Variables (cont.) variable_name = expression; –addition a + b  a + b –subtractiona - b  a - b –multiplicationa x b  a * b –divisiona / b  a / b –exponenta b  a ^ b

Changing the data format >> value = ; – format short  (default format) – format long  – format short e  e+001 – format long e  e+001

String Variables String variables contain a sequence of characters, like this s='This is a string' If you need an apostrophe in your string, repeat a single quote, like this: t='Don''t worry‘ And if you justwant to access part of a string, like the first 7 characters of s (defined above) use s(1:7)

Matlab Functions Matlab knows all of the standard functions found on scientific calculators and even many of the special functions. – cos(x) – sin(x) – tan(x) – acos(x) – asin(x) – atan(x) – atan2(y,x)

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

Matlab Functions The num2str() and int2str() functions – >> d = [ num2str(16) '-Feb-' num2str(2004) ]; – >> disp(d) – 16-Feb-2004 – >> x = 23.11; – >> disp( [ 'answer = ' num2str(x) ] ) – answer = – >> disp( [ 'answer = ' int2str(x) ] ) – answer = 23

Scripts Typing in commands in the command window is just the tip of the iceberg of what Matlab can do for you. Most of the work you will do in Matlab will be stored in files called scripts, or m-files, containing sequences of Matlab commands to be executed over and over again.

Scripts To make a script, create a new text file in Matlab by clicking on the empty document on the tool bar. Then save this file with a.m extensions (automatically added in Windows) in the directory where you want to store your Matlab scripts. Script file names cannot start with numbers, like 430lab1a.m You execute scripts by typing their name, and when Matlab receives the start of a number in a command it thinks a calculation is coming. Since something like 430lab1a is not a valid calculation, Matlab will give you an error if you try and name your scripts like this.

Running a Script Before you can execute a script, you need to point Matlab’s current folder to the place where your script is saved. Remember to save changes to your script before executing it (Ctrl-s is a quick way) You should nearly always begin your scripts with the following two commands: clear; close all; The clear command clears all variables fromMatlab’s memory and makes sure that you don’t have leftover junk active in Matlab that will interfere with your code. The close all command closes any figure windows that are open. Any line in a script that ends with a semicolon will execute without printing to the screen. For example, add these two lines of code to your test script – a=sin(5); – b=cos(5)

Input and Output To have a script request and assign a value to the variable N from the keyboard, put the command N=input(' Enter a value for N - ') To display printed results you can use the fprintf command fprintf(' N =%g ',N) Note that the stuff inside the single quotes is a string which will print on the screen; % is where the number you are printing goes; and the stuff immediately after % is a format code. A g means use the “best” format; if the number is really big or really small

Flow Control Constructs Logic Control: – IF / ELSEIF / ELSE Iterative Loops: – FOR – WHILE

The if, elseif and else statements The general syntax for the if structure is:  if logical expression 1 % some commands executed if logical_expression_1 is true elseif logical expression 2 % some commands executed if logical_expression_1 is false % but logical_expression_2 is true else % executed in all other cases end

Example: if no1>no2 disp([num2str(no1) '>' num2str(no2)]) elseif no1<no2 disp([num2str(no1) '<' num2str(no2)]) else disp([num2str(no1) '=' num2str(no2)]) end The if, elseif and else statements

The for loop syntax is useful to repeat execution of a certain block of code The for loop for variable=startvalue :stepsize : endvalue % some commands end Example: for i=1:1:5 disp(i) end for variable=startvalue :stepsize : endvalue % some commands end Example: for i=1:1:5 disp(i) end

The while loop i=0; while i<10 disp(i); i=i+1; end i=0; while i<10 disp(i); i=i+1; end The syntax of the while loop is the following: while logical_expression % some commands end

Creating MATLAB functions By creating a function m-file, you can add functions to MATLAB. The name ‘m-file’ is derived from the extension of such files, which must be.m. Using m-files, you can collect your own commands and execute them with a single command (which is the m-file name). Using input and output variables, the m-file can also communicate with MATLAB and other functions. An m-file has the following form  function [output1,output2,...]=myfunction(input1,input2,...)  Example: function [sum,avg]=sumavg(no1,no2) sum=no1+no2; avg=sum/2;  To access this function: [x,y]=sumavg(3,5)

Plot function >> a=[ 3 4 5;3 6 7;6 7 8] a = >> plot(a)

Matlab Graphs x = 0:pi/100:2*pi; y = sin(x); plot(x,y) xlabel('x = 0:2\pi') ylabel('Sine of x') title('Plot of the Sine Function')

Multiple Graphs t = 0:pi/100:2*pi; y1=sin(t); y2=sin(t+pi/2); plot(t,y1,t,y2) grid on

Notes The up-arrow key " will display previous commands. clc used to clears the command window

Yahoo group gnition_MUST gnition_MUST m