Logical Functions
Logical Functions
-5
Rate of Change
Selection Structures
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
Chapter 8
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or
transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
Objectives
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
After studying this chapter you
should be able to:
Understand how MATLAB interprets
relational and logical operators
100
400
500
100 200 300 400 500
family of commands
Understand the switch/case structure
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Structures
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
Sequence
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
Repetition
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
8.1 Relational and Logical Operators
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
Relational operators make those
300
400
comparisons
Logical operators allow us to
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Relational Operators
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
< Less than
<= Less than or equal to
> Greater than
100
400
500
100 200 300 400 500
== Equal to
~= Not equal to
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Comparisons are either true
or false
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
The results of a comparison are used in
selection structures and repetition
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
MATLAB compares corresponding
elements and determines if the
result is true or false for each
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
In order for MATLAB to decide a
-5
Rate of Change
-4.5
-4
-3.5
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Logical Operators
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
& and
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
~ not
100
| or
200
300
xor exclusive or
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
8.2 Flow Charts and Pseudo-Code
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
400
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Pseudo-code
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
comments in an M-file
400
500
100 200 300 400 500
Insert the appropriate MATLAB
code into the file between the
comment lines
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Pseudo-code Example
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Outline the steps
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
into a matrix
Create a table title
300
400
500
100 200 300 400 500
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Insert the MATLAB code
between the comments
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Flow Charting
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
complicated programs
Create a big picture graphically
100
200
Convert to pseudo-code
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
Simple Flow Chart Symbols
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
beginning of a section of
code
A parallelogram indicates
100
an input or output
A diamond indicates a
200
300
decision point
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Start
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
Define a vector
-3
-2.5
of miles/hour
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Calculate the
time, hour
ft/sec vector
This flowchart
Combine into a represents the
100
table mph to ft/s
200
Create an output
problem
300
400
table using disp
500
100 200 300 400 500
and fprintf
End
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change 8.3 Logical Functions
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
switch/case
400
500
100 200 300 400 500
And a series of logical functions
that perform many of the same
tasks
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change find
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change For example
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
heights
300
400
63, 67, 65, 72, 69, 78, 75
Which applicants meet the
500
100 200 300 400 500
criteria?
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
The find function returns the index number
Rate of Change
for elements that meet a criteria
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
index numbers
100
200
300
400
500
100 200 300 400 500
element values
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
index numbers
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
You could use the disp and fprintf
functions in this program to create a
Rate of Change
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
You could also make a table of those who
do not meet the height requirement
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
By combining relational and logical
operators you can create fairly
Rate of Change
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
They must also meet the height
300
400
requirement
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Applicant pool
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Height Age
time, hour
Inches years
63 18
67 19
100 65 18
72 20
200
300
400
500
100 200 300 400 500
69 36
78 34
75 12
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Lets use Pseudo-code to
plan this program
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
determine which applicants are
300
400
eligible
Use fprintf to create a table of
500
100 200 300 400 500
results
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
output, the intermediate calculations
300
were sent to the command window
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
The find command can
return either
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
element in a matrix
A matrix of the row numbers and the
column numbers identifying an
100
400
500
100 200 300 400 500
the row and column designation
[row, col] = find( criteria)
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Imagine you have a matrix of
patient temperature values
Rate of Change
measured in a clinic
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
200
300
400
500
100 200 300 400 500 100.1 99.3 97
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Use the find command to determine
which patients have elevated
Rate of Change
temperatures
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500 1 4
These elements refer7to the single
2 index number
5 identification
8 scheme
3 6 9
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
If we want the row and
column
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
3,1 3,2 3,3
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Flow charting and Pseudo-
code for find Commands
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1
-0.5
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
8.4 Selection Structures
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
situations where if is the
300
400
appropriate process to use
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Simple if
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
if comparison
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
statements
end
100
For example.
if G<50
200
300
400
500
100 200 300 400 500
disp(G is a small value equal to:)
disp(G);
end
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change If statements
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
matrix?
300
400
The comparison is only true if it is
500
100 200 300 400 500
true for every member of the array
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Consider this bit of code
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
G=[30,55,10]
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
if G<50
disp(G is a small value equal to:)
100
disp(G);
200
300
400
end
500
100 200 300 400 500
The code inside the if statement is
not executed, because the
comparison is not true!!
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
This statement is
false because at
least one of the
100
elements in G has
200
a value >= 50
300
400
500
100 200 300 400 500 Therefore the code
inside the if statement
does not execute.
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
This statement is
-1.5
-1
-0.5
;
true because all of
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
the elements in G
are < 70
100
200
300
The output would have
400
been cleaner if we had
500
100 200 300 400 500
suppressed line 1 by
adding a semicolon to
the code.
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change The if/else structure
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
400
500
What if instead you want to execute an
alternate set of code if the condition is
100 200 300 400 500
false?
MATLAB for Engineers 3E, by Holly Moore. 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Flow chart of an if/else
structure
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
True False
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
Comparison
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Use an if structure to
calculate a natural log
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
positive
If it is, calculate the natural log
100
If it isnt, send an error message to
the screen
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change M-file Program
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Interactions in the Command
Window
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change The if/else/elseif structure
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
selection criteria
For example
100
200
Write a program to determine if an
300
400
applicant is eligible to drive
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Start
Sorry
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
if age<16 True Youll have
-3
-2.5
-2
-1.5
to wait
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
elseif
time, hour
You may
age<18 True
have a youth
license
elseif
300
else
400
Drivers over 70
500
100 200 300 400 500 require a
special license
End
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-3.5
-3
-2.5
programs making
-2
-1.5
-1
-0.5
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change As a general rule
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
Combine if structures with a
300
400
repetition structure
Repetition structures are
500
100 200 300 400 500
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
if/else/elseif structure
The code is generally easier to read
100
This structure allows you to choose
200
300
between multiple outcomes, based on
400
500
some criterion, which must be exactly
true
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change When to use switch/case
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
strings than with numbers.
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
The structure of switch/case
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
switch variable
-0.5
0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
case option1
code to be executed if variable is exactly
equal to option 1
case option2
code to be executed if variable is exactly
equal to option 2
100
200
case option_n
300
400
code to be executed if variable is exactly
500
100 200 300 400 500
equal to option n
otherwise
code to be executed if variable is not
equal to any of the options
end
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Suppose you want to
-5
Rate of Change
determine what the airfare is
Rate of temperature change, degrees/hour
-4.5
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
300
second field.
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Menu
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
This function causes a menu box
300
400
to appear on the screen with a
500
100 200 300 400 500
series of buttons defined by the
programmer.
input = menu(Message to the user,text for button 1,text for button 2, etc)
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
This means you dont need the
300
400
otherwise portion of the
500
100 200 300 400 500
switch/case structure
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
Note that the otherwise portion of the
switch/case structure wasnt used
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
When you run this code a
menu box appears
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
Instead of entering
your choice from
the command
window, you select
one of the buttons
from the menu
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change If I select Honolulu
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Summary
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
categorized as
sequences
100
selection structures
200
300
400
repetition structures
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Summary Sequence
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Summary Selection
Structure
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Summary Repetition
Structures
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Summary Relational
Operators
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
>
400
>=
500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Summary Logical
Operators
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
logical operators
&& and
100
|| or
200
300
400
~ not
500
100 200 300 400 500
xor exclusive or
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Summary Logical
Functions
Rate of Change
-5
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
400
500
100 200 300 400 500
-4.5
-4
-3.5
-3
-2.5
-2
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
if
300
400
else
500
100 200 300 400 500
elseif
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Summary switch/case
Rate of temperature change, degrees/hour
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
structure
Commonly used with menu
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.