Script Files; User Input; Output
ITP 168 Spring 2016
Week 2, Lecture 1
Last time
Create and use variables
Camel case/naming rules
Using the workspace
Saving the workspace
Loading a workspace
Script Files
Command-line is great for testing
Want to ex

Script Files; User Input; Output
ITP 168 Spring 2015
Week 2, Lecture 1
Last time
Create and use variables
Camel case/naming rules
Using the workspace
Saving the workspace
Loading a workspace
Script Files
Command-line is great for testing
Want to ex

Cell Arrays
ITP 168 Fall 2015
Week 6 Lecture 1
Cell Arrays
Theyre arraysof cells
Well, whats a cell?
Think of them as containers of stuff
Cells
What kinds of stuff can they contain?
EVERYTHINGquite frankly
Cell Arrays
Cells can contain ANY type of MA

Functions
ITP 168 Fall 2015
Week 9 Lecture 2
Overloading Input
Functions may be called in various ways using input overloading
Our example was creating a standard deviation function that
either does corrected or uncorrected sample standard deviations
H

Array Creation; Array Operations
ITP 168 Spring 2015
Week 3 Lecture 2
2D Arrays
2D arrays are called matrices
Are like collections of vectors
Think: Excel Spreadsheet
> X = [1 2 3; 4 5 6; 7 8 9]
X =
1
4
7
2
5
8
3
6
9
Matrices
Dont need to be square ma

Basics of Using MATLAB; Variables; Screen Output
ITP 168 Fall 2015
Week 1, Lecture 2
Last time
Saw how we could use MATLAB as a calculator
Did addition, subtraction, trig
Learned precision
Storing information
Dont want our computations to go away
We

Structures
ITP 168 Fall 2015
Week 6 Lecture 2
Structures
Think about a collection of attributes shared by one common
object
The structure defines that an object has certain attributes, and
those attributes have values
Take a student at USC
Structures

Logical Operators; Logic Arrays
ITP 168 Fall 2015
Week 4 Lecture 2
Logical Operators
Try This:
2.0 1.1 = 0.9
True?
Try it:
> (2.0 1.1) = 0.9;
If you get 0, its false, if you get 1, its true.
Handling Floats
Its all about the conversion from a decimal

Loop Structure; While Loop; For Loop
ITP 168 Fall 2015
Week 5 Lecture 1
Loops
The easiest way to repeat something
All loops have the same parts:
Initialization
Evaluation
Execution
Update
Termination
Not always in this order
While Loop
Easiest type of

Script Files; User Input; Output
ITP 168 Fall 2015
Week 2, Lecture 1
Last time
Create and use variables
Camel case/naming rules
Using the workspace
Saving the workspace
Loading a workspace
Script Files
Command-line is great for testing
Want to exec

File I/O
ITP 168 Fall 2015
Week 7 Lecture 1
File Import
Easiest way: use the import data button
Second easiest way: uiimport
Import Data Button
Import Data Button
Import Data Button
Import Data Button
Import Data Button
Using importdata()
importdata(fil

Nesting Loops; Problem-Solving Examples
ITP 168 Fall 2015
Week 5 Lecture 2
Loops
Two types of loops
While loops run as long as an expression is true
For loops run as many iterations as there are columns in the array
(vector or matrix)
Validating Input

Array Creation; Array Operations
ITP 168 Spring 2015
Week 3 Lecture 2
Vector Length
Can be unbearably long
Can be uselessly short
Can be in between
Always important to know the length
Vector Length
Length function: length()
> length([1 2 3 4])
ans =

Flow of Control; If-Else; Switch Block
ITP 168 Spring 2015
Week 4 Lecture 1
Flow of Control
An elegant solution to decision-making in programming
Also, a key factor in catching user errors before they cause drastic
failures
Consider this example
Exampl

Review
Output fprintf()
The function fprintf() takes whatever string or character is in the
parentheses and writes that exactly to the command window
Must have a string! Cannot have a number!
But you can have numbers in your strings!
Since we can stor

Introduction to MATLAB
ITP 168x (2 Units)
Spring 2016
Objective
Fundamentals of MATLAB: a high-performance numeric computation and visualization
environment. Overview of linear algebra and matrix manipulation; using 2-D and 3-D plotting
routines; programm

Cell Arrays
ITP 168 Spring 2015
Week 5 Lecture 1
Cell Arrays
Theyre arraysof cells
Well, whats a cell?
Think of them as containers of stuff
Cells
What kinds of stuff can they contain?
EVERYTHINGquite frankly
Cell Arrays
Cells can contain ANY type of

Basics of Using MATLAB; Variables; Screen Output
ITP 168 Spring 2015
Week 1, Lecture 2
Last time
Saw how we could use MATLAB as a calculator
Did addition, subtraction, trig
Learned precision
Storing information
Dont want our computations to go away
W

Logical Operators; Try/Catch; Logic Arrays
ITP 168 Spring 2015
Week 4 Lecture 2
Logical Operators
Try This:
2.0 1.1 = 0.9
True?
Try it:
> (2.0 1.1) = 0.9;
If you get 0, its false, if you get 1, its true.
Handling Floats
Its all about the conversion f

Structures
ITP 168 Spring 2015
Week 5 Lecture 2
Structures
Think about a collection of attributes shared by one common
object
The structure defines that an object has certain attributes, and
those attributes have values
Take a student at USC
Structures

Functions
ITP 168 Fall 2015
Week 9 Lecture 1
Functions Vs. Scripts
Script files:
Take no input
Give no output arguments
Operate on variables in the workspace
Function files:
Contain function definition line
Take in input
Return output arguments
Varia

Array Creation
ITP 168 Spring 2015
Week 3 Lecture 1
Arrays
Your lab asked you to take in 5 pieces of information
You have to create 5 variables to hold it
So there is a 1:1 ratio of variables to pieces of info
What if I asked for 10,000 pieces of info

Functions
ITP 168 Fall 2015
Week 7 Lecture 2
Functions
Functions are tasks
Allow us to break up code into manageable, repeatable chunks
Help de-clutter our code
Functions
Think of a car and its many functions
Cars have an accelerate function
Cars ha

function tumor(m,n)
%check m and n. Positive scalar.
if ~isscalar(m) | ~isscalar(n)
error('Inputs must be scalar values');
end;
if m < 0 | n < 0
error('Inputs must be positive');
end;
theta = linspace(0,2*pi,100);
phi = linspace(0,pi,100);
[thetaGrid, phi

%cfw_
Milad Nowrozani
ITP 168 - Spring 2016
Lab 5
[email protected]
Revision History
Date
Change
Name
-2/04/2016
Original
Milad Nowrozani
%
fprintf('Answer the following arithmetic question as fast as possible.\n Good
luck!\n')
num1 = randi(10);
num2 = ran

%cfw_
Milad Nowrozani
ITP 168 - Spring 2016
Lab 7
[email protected]
Revision History
Date
Change
Name
-2/11/2016
Original
Milad Nowrozani
%
valInput = false;
while (~valInput)
nRow = input('Enter the number of rows: ');
if (nRow = 0)
nRow = input('Cannot b