حمیدرضا پوررضا مروری بر MATLAB. محاسبات ساده >> ((40+60)*11-100)/20 ans = 50 >> x=5 x = 5 >> y=10; >> x*y^2 ans = 500 H.R. POURREZA 2 Variable naming.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
ES 314 Lecture 2 Sep 1 Summary of lecture 1: course overview intro to matlab sections of Chapters 2 and 3.
What is MATLAB ? MATrix LABoratory Developed by The Mathworks, Inc ( Mathworks, Inc Interactive, integrated, environment –for.
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Introduction to MATLAB
Matlab intro The Environment
An Introduction to Scilab Tsing Nam Kiu 丁南僑 Department of Mathematics The University of Hong Kong 2009 January 7.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
M ATLAB Tutorial Course 1. Contents Continued  Desktop tools  matrices  Logical &Mathematical operations  Handle Graphics  Ordinary Differential.
Introduction to MATLAB Zongqiang Liao Research Computing Group UNC-Chapel Hill.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
1 = MATLAB Mathematics + Laboratory + Dan Ophir, Ph.D. Cell.: Civil Engineering =
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
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.
1 Yangon Technological University Department of Mechanical Engineering Computer Application In Mechanical Engineering I ME Dr. Yin Yin Tun Deputy.
CMPS 1371 Introduction to Computing for Engineers MatLab.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
OUTLINE Overview Numbers, variables and similar in Matlab
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
Matlab. Textbooks Required:, by Palm (3 rd edition) Required: Introduction to MATLAB for Engineers, by Palm (3 rd edition)
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Lecture (5) Programming (2) Eng. Osama Talaat 1. Announcement  M-Files are available:  Download the file from the course page
Introduction to MATLAB Zongqiang Liao Research Computing Group UNC-Chapel Hill.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
Introduction to MATLAB Session 2 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2010.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
CS112 Scientific Computation Department of Computer Science Wellesley College Storing Values for Safe Keeping Variables and their Values.
MATLAB Programming. Why MATLAB is used ? It can use a simple instruction to compute a very complex mathematical function. It provides high resolution.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)
NoViC, Dept. of Mechanical Eng Acoustics Lab., NoViC 1. Download Matlab 2.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Basics of MATLAB 2- Programming in MATLAB By DR. Wafaa Shabana
Arithmetic Operations
Introduction to MATLAB
تهیه و تنظیم: فاطمه قاسمی دانشگاه صنعتی شریف – پاییز 86
Matrices and Arrays.
Seminar 1 for DCSP Using Matlab.
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Introduction To MATLAB
Net 222: Communications and networks fundamentals (Practical Part)
آموزش مقدمات MATLAB سیگنال ها و سیستم ها دانشگاه صنعتی شریف پائیز 86
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
MATH 493 Introduction to MATLAB
بسم الله الرّحمن الرّحيم
تهیه و تنظیم: فاطمه قاسمی دانشگاه صنعتی شریف – پاییز 86
آموزش مقدماتی نرم افزار MATLAB
Introduction to MATLAB
CS 175 Project in AI Discussion -- matlab
Plotting Signals in MATLAB
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
-seminar 1 for digital signal processing
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Presentation transcript:

حمیدرضا پوررضا مروری بر MATLAB

محاسبات ساده >> ((40+60)*11-100)/20 ans = 50 >> x=5 x = 5 >> y=10; >> x*y^2 ans = 500 H.R. POURREZA 2 Variable naming rules 1- case sensitive 2- maximum length is 31 characters 3- must start with letter 4- can not contain any symbols Reserved Word List for end if while function return elseif case otherwise switch continue else try catch global persistent break

توابع محاسباتی >> cos(pi); >> exp(5); % e 5 >> log2(8); % 8=2 3 >> sqrt(100); >> abs(3+4i); >> angle(3+3i); >> floor(9.9); >> round(3.6); >> rem(10,4); H.R. POURREZA 3

توابع محاسباتی >> [ang,r,z]=cart2pol(1,1,1); >> nchoosek(5,3); % N!/K!(N-K)! >> whos >> clear >> whos >> format long >> pi >> format short >> pi H.R. POURREZA 4

توابع M-File Choose New from the File menu and select M-file H.R. POURREZA 5 function amount = wage(hours, payRate) % Will calculate the weekly wage amount = 40*payRate+(hours-40)*1.5*payRate; >> type wage >> help wage >> wage(40,10) >> wage(40,2000); >> am=wage(40,2000)

توابع M-File – استفاده از IF H.R. POURREZA 6 function amount = wage(hours, payRate) fprintf('Hi! My name is WageCalculator and I will calculate how much you earned last week.\n'); name = input('What is your name?\n','s'); fprintf('Nice to meet you %s.\n',name); Max_hours=40; Overtime_rate=1.5; if hours>=Max_hours amount = Max_hours*payRate+(hours- Max_hours)*Overtime_Rate*payRate; else amount = hours*payRate; end

اندیسهای ماتریس >> A=[]; >> A=[1 2 3; 4 5 6; 7 8 9]; >> A=[1 2 3; 4 5 6; 7 8 9] A= >> Mm=A*A;% ضرب ماتریسی Mm = H.R. POURREZA 7

اندیسهای ماتریس >> Ma=A.*A% ضرب آرایه ای Ma = >> Dm=A/A;% تقسیم ماتریسی >> DA=A./A;% تقسیم آرایه ای >> 1: >> X=1:N; >> X=colon(1,N); H.R. POURREZA 8

اندیسهای ماتریس >> 100:-10: >> C3=A(:,3) C3 = >> R2=A(2,:) R2 = H.R. POURREZA 9

اندیسهای ماتریس >> T2=A(1:2,1:3) T2 = >> T3=T2' T3 = >> S=sum(B(1:k,j)); H.R. POURREZA 10

تولید ماتریس >> zeros(M,N)%generate an MxN matrix of zeros >> ones(M,N)%generate an MxN matrix of ones >> rand(M,N)%generate an MxN whose entires are %uniformly-distributed random %numbers in the interval [0.0,1.0] >> randn(M,N)%generate an MxN whose entires are %normally-distributed random %numbers with mean 0 and var. 1 H.R. POURREZA 11

تولید ماتریس >> A=5*ones(3,3) A = >> B=rand(2,4) B = >> H.R. POURREZA 12

ادغام ماتریسها (Matrix Concatenation) >> B = [1 2;3 4]; >> C = [B B;B+4 B-1] C = >> H.R. POURREZA 13

حذف سطر و ستون از ماتریسها >> C(2, :) = []%delete the second row of C C = >> C(:, 1:3:4) = [] C = >> H.R. POURREZA 14

دریافت خصوصیات ماتریسها >> B = [5 1 2; 3 9 4; 7 6 8]; >> max(B) ans = >> max(max(B)) ans = 9 >>max(B(:)); >> S = size(B) S = 3 3 H.R. POURREZA 15

دریافت خصوصیات ماتریسها >> D = B(2, :) D = >> size(D) ans = 1 3 length(D) ans = 3 >> ndims(B) ans = 2 H.R. POURREZA 16

For-end >> [R,C]=size(B); >> Avg=0; >>for r=1:R for c=1:C Avg=Avg+B(r,c); end >>Avg=Avg/(R*C) Avg = >> >>lookfor average >> pause H.R. POURREZA 17

نمایش >> plot(x); Try: x = 0:0.1:2*pi; y=sin(x); plot(x,y) grid on hold on plot(x,exp(-x),'r:*'); title('2-D Plots'); xlabel('Time'); ylabel('Sin(t)'); text(pi/3,sin(pi/3),'<--sin(\pi/3)') legend('Sine Wave','Decaying Exponential'); H.R. POURREZA 18

نمایش >> plot(x); Try: x=0:.1:2*pi; subplot(3,1,1); plot(x,sin(x)); subplot(3,1,2); plot(x,cos(x)); subplot(3,1,3) plot(x,exp(-x)); H.R. POURREZA 19

مثال یک clc; clear all; close all; t=-2:1:2; y=[zeros(1,2),ones(1,1),zeros(1,2)]; subplot(2,2,1); stem(t,y); ylabel('Amplitude -->.'); xlabel('(a) n -->.'); H.R. POURREZA 20 تولید چند سیگنال گسسته:

مثال یک % ################################ n=input('enter the N value'); t=0:1:n-1; y1=ones(1,n); subplot(2,2,2); stem(t,y1); ylabel('Amplitude -->.'); xlabel('(b) n -->.'); % ################################ n1=input('enter the length of ramp sequence'); t=0:n1; subplot(2,2,3); stem(t,t); ylabel('Amplitude -->.'); xlabel('(c) n --.>'); H.R. POURREZA 21 تولید سیگنال [u(n)-u(n-N)]: تولید سیگنال شیب:

مثال یک % ################################ n2=input('enter the length of exponential sequence'); t=0:n2; a=input('enter the a value'); y2=exp(a*t); subplot(2,2,4); stem(t,y2); ylabel('Amplitude -->.'); xlabel('(d) n -->.'); H.R. POURREZA 22 تولید نمایی:

مثال دو % ################################ t=0:.01:pi; y=sin(2*pi*t); figure(2); subplot(2,1,1); plot(t,y); ylabel('Amplitude --.>'); xlabel('(a) n --.>'); % ################################ t=0:.01:pi; y=cos(2*pi*t); subplot(2,1,2); plot(t,y); ylabel('Amplitude -->.'); xlabel('(b) n --.>'); H.R. POURREZA 23 تولید تابع سینوس: تولید تابع کسینوس:

مثال سه clc; clear all; close all; x=input('enter the 1st sequence’'); h=input('enter the 2nd sequence'); y=conv(x,h); figure;subplot(3,1,1); stem(x);ylabel('Amplitude --.'); xlabel('(a) n --.'); subplot(3,1,2); stem(h);ylabel('plitude --.'); xlabel('(b) n --.'); subplot(3,1,3); stem(y);ylabel('Amplitude --.'); xlabel('(c) n --.'); disp('The resultant signal is');y H.R. POURREZA 24

مثال سه enter the 1st sequence’[1 2] enter the 2nd sequence[1 2 4] The resultant signal is y = H.R. POURREZA 25

مثال چهار clc; clear; % Function definition stepsize = 0.01; t1 = [-1 : stepsize : 3]; f = t1>=0 & t1<=2; t2 = [-1 : stepsize : 2]; h = t2>=0 & t2<=1; % Convolution t = [t1(1)+t2(1) : stepsize : t1(end)+t2(end)];) g = zeros(size(t)); H.R. POURREZA 26 محاسبه کانولوشن برای دو سیگنال زیر:

مثال چهار for i = 1 : length(t) if t(i) <= 0 g(i) = 0; elseif t(i) <= 1 tau = [0 : stepsize : t(i)]; f_times_h = ones(1,length(tau)); g(i) = trapz(tau,f_times_h); elseif t(i) <= 2 tau = [t(i)-1 : stepsize : t(i)]; f_times_h = ones(1,length(tau)); g(i) = trapz(tau,f_times_h); elseif t(i) <= 3 tau = [t(i)-1 : stepsize : 2]; f_times_h = ones(1,length(tau)); g(i) = trapz(tau,f_times_h); else g(i) = 0; end H.R. POURREZA 27

مثال چهار % Plots figure; subplot(2,2,1); plot(t1,f,'LineWidth',2); xlabel('t'); ylabel('f(t)'); ylim([0 1.5]); subplot(2,2,2); plot(t2,h,'LineWidth',2); xlabel('t'); ylabel('h(t)'); ylim([0 1.5]); subplot(2,2,3:4); plot(t,g,'LineWidth',2); xlabel('t'); ylabel('g(t)=f(t)*h(t)'); ylim([0 1.5]); H.R. POURREZA 28

مثال چهار H.R. POURREZA 29

مثال پنج clear; t = -1:0.01:3; u_t = t>=0; u_t_1 = t>=2; f = u_t - u_t_1; I1 = trapz(t,f) t = 0:0.01:pi/2; g = sin(2*t); I2 = trapz(t,g) I1 = 2 I2 = H.R. POURREZA 30 محاسبه دو سیگنال زیر:

جعبه ابزار پردازش تصویر >> f = imread(' d:\images\fig4.jpg ', 'jpg'); >> size(f) ans= >> imwrite(f,' d:\images\fig4.jpg ', 'jpg'); >>imshow(f) >>g=rgb2gray(f); >>g=mat2gray(f); H.R. POURREZA 31