9:10
BMEN.1200 BME Application Programming
Data & Plotting (Chapter 1+5)
Introduction
Overview of MATLAB and Knovel introduced
Introduction to data types in MATLAB
Agenda
Recap Previous Material
Diving Deeper into Data Types
Ranges of Numeric Data Types (integers and floats)
whosfunction for data type bookkeepingDisplaying Data using
disp()Data Type Casting
Boolean Examples
Loading and Saving Data
Activities 1.4 - 1.5, 5.2, and 5.5 from the chapter text
Key Data Types
Variable Types
Floating Point: e.g., 1.234 (single, double depending on precision)
Integer: e.g., 3 (int8, int16, int32, int64 based on storage bits)
Character: e.g., 'a' (char)
Boolean: e.g., true (logical)
Arrays and Matrices
Data Structure
Scalar, array, and matrix variables
1D arrays called vectors in MATLAB
Array Operations
MATLAB allows element-wise operations: e.g.,
c = 2; d = [1 3 4 2 5];Different operations:
d + 3,d.^3,d.*e
Creating Arrays
Methods
Using colon operator:
x = 1:100;Using
linspace:x = linspace(start, end, number of values);
Accessing and Displaying Arrays
Accessing Elements
Syntax:
array(index)Example:
d(3)or setting valued(3) = 0
Displaying Data
Use
disp(X)to display arraysExample:
disp(y);
Code Hygiene
Commenting
Multi-line comments:
%{...%}Single line comments:
%
Suppressing Code
Use semicolons to suppress output and improve performance
Help Functions
Use the
helpcommand for function usage:Example:
help blank
Data Types in MATLAB
Common Types
Floating Point, Integer, Boolean, Character, Strings
Use
whosto review variable types and sizesExample:
whos a b c
Numeric Types
Fundamental Numeric Types
Two main types:
Integers (unsigned & signed)
Floating point (single precision: 32 bits; double precision: 64 bits)
Floating-Point Arithmetic
Common issues due to finite precision in computers
Example code operations:
sqrt(a)with different types
Converting Between Types
Various casting methods:
Between Number and Character
Between Number and Logical
Safer to use explicit function calls for conversions
Especial Values
Inf: Represents infinity
NaN: Represents 'Not a Number'
Test functions:
isinf()andisnan()for identification
Loading and Saving Data
Use
dlmwritefor writing arrays to text filesLoad and save workspace components:
Example operations:
save('newdata.mat'...)
Homework Assignments
Complete exercises from Chapters 1-5:
HW1 due September 17
Exercises 1.1 - 1.4, 5-8, 12-15, and Chapters 27-28