Ying shen School of software engineering tongji university

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

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.
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
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)
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Matlab tutorial course Lesson 2: Arrays and data types
Matlab tutorial course Exercises 2:. Exercises Copy the script ‘face_points.m’ from my webpage into your ‘scripts’ folder Create a new folder in your.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
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.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
COMP 116: Introduction to Scientific Programming Lecture 6: Scripts and publishing, Creating matrices.
Active-HDL Interfaces Debugging C Code Course 10.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 9 Macros And Visual Basic For Applications.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Matlab
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Intro to Matlab Yipei Wang & Qihui Li {yipeiw,
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Matlab Workshop Getting Started.
Introduction to MATLAB
Introduction to Matlab
Release Numbers MATLAB is updated regularly
BAHASA PEMROGRAMAN MATLAB as an Engineering Tool & Programming Language a lecture note for Civil Engineering students of PETRA Christian University Doddy.
Computer Application in Engineering Design
Introduction to Matlab
Statistical Computing in MATLAB
Introduction to MATLAB
Chapter 4 MATLAB Programming
Scripts & Functions Scripts and functions are contained in .m-files
Introduction to MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Matlab Workshop 9/22/2018.
Introduction To Matlab Class 1
Lecture 1: Introduction
StatLab Matlab Workshop
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Matlab tutorial course
Lecture 2 Introduction to MATLAB
MATLAB How to use (using M-files)
Digital Image Processing
Fourth Year – Software Engineering
funCTIONs and Data Import/Export
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Debugging Visual Basic Programs
CSCI N207 Data Analysis Using Spreadsheet
Using Script Files and Managing Data
MATLAB Introduction MATLAB can be thought of as a powerful graphing calculator but with a lot more buttons! It is also a programming language, commands.
MATLAB stands for MATrix LABoratory.
Chapter 2 MATLAB Environment
Presentation transcript:

Ying shen School of software engineering tongji university Matlab Tutorial Ying shen School of software engineering tongji university

Development Environment Current working directory Script editor Workspace The desktop includes these panels: • Current Folder — Access your files. • Command Window — Enter commands at the command line, indicated by the prompt (>>). • Workspace — Explore data that you create or import from files. Command window

Commands Create a variable a = 1 b = 2 c = a+b d = cos(a) sin(a)

Character Strings Assign a string to a variable myText = 'Hello, world'; % disp(myText); otherText = 'You''re right' % disp(otherText); f = 71; c = (f-32)/1.8; tempText = ['Temperature is ',num2str(c),'C'] % disp(tempText)

Calling Functions Functions A = [1 3 5]; max(A)

Loops and Conditional Statements Within a script, you can loop over sections of code and conditionally execute sections using the keywords for, while, if, and switch nsamples = 5; npoints = 50; for k = 1:nsamples currentData = rand(npoints,1); % create an array with % random values sampleMean(k) = mean(currentData); % mean value end overallMean = mean(sampleMean)

Matrices and Arrays Array Creation Matrix and Array Operations a = [1 2 3 4] % a row vector a = [1 2 3; 4 5 6; 7 8 10] % a square matrix z = zeros(5,1) % a column vector containing 5 zeros Matrix and Array Operations a + 10 sin(a) a' p = a*inv(a) p = a.*a

Matrices and Arrays Concatenation Array indexing A = [a, a] A = [a; a] A = magic(4) % a 4*4 magic square A(4,2) A(8) A(4,2) = 17 A(3,:) 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A =

Matrices and Arrays Deleting Rows and Columns A(:, 2) = [] % A is a 4*3 matrix 16 3 13 5 10 8 9 6 12 4 15 1 A =

Draw Lines Draw a line x = 0:pi/100:2*pi; y = sin(x); figure % opens new figure window plot(x,y)

Draw Lines Draw a line x = 0:pi/100:2*pi; y = sin(x); figure % opens new figure window plot(x,y)

Draw Lines Draw a line figure; [x, y] = getline; line(x,y); % press Enter

Draw A Rectangle Rectangle('position', pos) axis([0 10 0 10])

Load An Image Example A = imread('moonwalk.jpg'); image(A);

Load Images Example img = cell(4,1); for i = 1:4 img{i} = imread(['bg' num2str(i) '.png']); end hold on; % draw images in the same figure image(0,0,img{1}); image(200,0, img{2}); image(0,100,img{3}); image(200,100,img{4});

Load Images Example img = cell(4,1); for i = 1:4 img{i} = imread(['bg' num2str(i) '.png']); end hold on; image(0,0,img{1}); image(200,0, img{2}); image(0,100,img{3}); image(200,100,img{4});

Programming and Scripts Create a new script

Programming and Scripts A sample script

Programming and Scripts Save the script

Programming and Scripts Run the script

Programming and Scripts Run the script

Programming and Scripts Set a breakpoint

Programming and Scripts Set a breakpoint

Programming and Scripts Set a breakpoint

Exercise Run previous examples Finish the following tasks: Task 1: Draw an oval; (x=acos(θ) y=bsin(θ)) Task 2: Load a series of images; Display one image each time and change to the next image when the right mouse button is clicked; Mark out all the faces in different images by dragging rectangles; hint: getrect; strcmp(get(gcf,'SelectionType'),'alt')