Lecture 2 - Lecture 2 Comments Variables and Operators BMEn...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
9/13/2010 1 Lecture 2: Comments, Variables and Operators BMEn 2401 Programming for Biomedical Engineers Rich Beck September 14, 2010 Today’s Lecture First steps of Programming in MATLAB Comments Variables Operators Introduction information Cell Mode MATLAB logistics for HW Controlling Output Controlling Input 2 Art of Program Writing A computer program consists of: Commands which MATLAB executes Order and group these in a logical way Comments which MATLAB ignores, but makes clear to you and others what is going on the sequence of commands 3 A good program is well-commented and easy to understand.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9/13/2010 2 Your First Program Launch MATLAB File → New → Blank M-file/Script Create the following M-file % This is my first Program % r is the radius of a circle % Area is the area of the circle r = 2.4 Area = 3.1415 * r ^ 2 Debug → Save and Run 4 Everything to the right of a “ % ” in the program line will be considered as a comment and will not be executed. Comments % This is my first Program % r is the radius of a circle % Area is the area of the circle r = 2.4 Area = 3.1415 * r ^ 2 Explain meaning of variables Explain meaning of commands Commenting your code is absolutely essential! A well-commented code is easy to understand and modify later. 5 A variable’s name consists of a letter followed by letters, digits, or underscore “_” Variables % This is my first Program % r is the radius of a circle % Area is the area of the circle r = 2.4 Area = 3.1415 * r ^ 2 6 r = 2.4000 Area = 18.0950 Each variable has an associated value (Output)
Background image of page 2
9/13/2010 3 Some Types of Variables Scalar Variables Created by typing or assigning a single number Example: r = 2.4 Area = 3.1415 * r ^ 2 r = 2.4000 Area = 18.0950 String Variables Created by typing characters within single quotes Example: s = 'The area of the circle is:' s = The area of the circle is: 7 (Output) (Output) MATLAB Workspace All of the variables created by script files (basic M- files) are available in the MATLAB Workspace. 8
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Lecture 2 - Lecture 2 Comments Variables and Operators BMEn...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online