Post on 19-Jan-2016
transcript
Introduction to MATLABSection2 , statistics courseThird 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!!
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
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.
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!
M-files scripts: PLOT EXAMPLE
M-files scripts: subplot example
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
Anatomy of the function
•Try out this simple example:(write it in an m-file
Scripts vs. Functions
Inputs and outputs from functions
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)
Data Analysis functions
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