introduction to matlab section2, statistics course third year biomedical dept. dina el kholy, ahmed...

15
Introduction to MATLAB Section2 , statistics course Third year biomedical dept . Dina El Kholy, Ahmed Dalal

Upload: gerard-mason

Post on 19-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Introduction to MATLABSection2 , statistics courseThird year biomedical dept.Dina El Kholy, Ahmed Dalal

Page 2: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Contents•Error messaged appearing at the console•M-files•Stem•Subplot,stem,subplot•Basic statistical functions•Functions•Find•Loading mat files•Fprintf , input•ECG data file and draw it: assignment!!

Page 3: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

M-files

•Text files containing MATLAB code.

•Useful for complex tasks.

•we can store the typed input into a file and tell MATLAB to get its input from that file.

•Extension: .m

Page 4: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

M-files

•If an m-file contains MATLAB statements just as you would type them into MATLAB, they are called scripts.

•M-files can also accept input and produce output, in which case they are called functions.

•The MATLAB executes the instructions, just as if you had typed them in the command window.

Page 5: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

M-files scripts : simple examples• Create an m-file(using the MATLAB text editor)• Type t he following statement in it

• Save it by the name example1.m• Run the script by typing the filename example1

in the command window• Note that when execution completes, the

variables (A, b, and x) remain in the workspace. Type whos to make sure!

Page 6: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

M-files scripts: PLOT EXAMPLE

Page 7: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal
Page 8: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

M-files scripts: subplot example

Page 9: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

M-files functions

•functions are programs (or routines) that accept input arguments and return output arguments

•Each M-file function has its own area of workspace, separated from the MATLAB base workspace

Page 10: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Anatomy of the function

•Try out this simple example:(write it in an m-file

Page 11: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Scripts vs. Functions

Page 12: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Inputs and outputs from functions

Page 13: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Input to scripts

•The variable is defined in the script file.•The variable is defined in the command

prompt meaning that it exists in the workspace before you run the script.

•The variable is entered when the script is executed using the built-in input function.(Check it out)

Page 14: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Data Analysis functions

Page 15: Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal

Assignments

•Read & understand the help to the functions in the data analysis functions slide and summarize what you understand about each function in a report. Try to use this function in the MATLAB to make sure you understand them(you are supposed to hand in this report)

•Learn what are the .mat files :▫Load the file(ECG.mat) into MATLAB and

plot the signal