100 about matlabstaff.iium.edu.my/.../ece1322_matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5...

102
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. 100 200 300 400 500 100 200 300 400 500 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 Rate of Change time, hour Rate of temperature change, degrees/hour About MATLAB Chapter 1

Upload: others

Post on 28-May-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r About MATLAB

Chapter 1

Page 2: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Objectives

After studying this chapter you should be able to:

• Understand what MATLAB is and why it is widely used in engineering and science

• Formulate problems by using a structured problem-solving approach

Page 3: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

What’s in this Chapter?

• What is MATLAB?

• How is MATLAB used in

industry?

• Problem Solving in

Engineering and Science

Page 4: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Section 1.1

What is MATLAB?

• MATLAB is one of a number of commercially available, sophisticated mathematical computation tools

• Others include

• Maple

• Mathematica

• MathCad

Page 5: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

MATLAB excels at

• Numerical calculations

• Especially involving matrices

• Graphics

• MATLAB stands for

Matrix Laboratory

Page 6: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Why MATLAB

• Easy to use

• Versatile

• Built in programming language

• Not a general purpose language

like C++ or Java

Page 7: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

MATLAB was originally

written in Fortran, then later

rewritten in C

Page 8: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Section 1.2

How is MATLAB used in

Industry?

• Widespread, especially in the

signal processing field

• Tool of choice in Academia for

most engineering fields

• Some examples….

Page 9: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Electrical Engineering

These images simulate the visual system used in a housefly

brain to detect collisions. The techniques developed are

being used in autonomous robot systems that depend upon

vision for navigation. The data was processed using MATLAB

Page 10: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Biomedical Engineering

These images were created from MRI scan data using MATLAB.

The actual data set is included with the standard MATLAB

installation, allowing you experiment with manipulating the data

yourself.

Page 11: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Fluid Dynamics

Results from a finite element analysis code were post processed

using MATLAB to create this image.

Page 12: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Summary

• MATLAB is widely used

• MATLAB is easy to use

• A systematic problem solving

strategy makes it more likely

you’ve found the right answer

Page 13: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r MATLAB Environment

Chapter 2

Page 14: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

In this chapter we’ll…

• Get started with MATLAB

• Explore the MATLAB windows

• Solve some problems using

MATLAB

• Learn how to save our work

Page 15: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Section 2.1

Getting Started

• In Windows or Apple operating systems

click on the desktop icon

• In Unix type

MATLAB

At the shell prompt

Page 16: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Section 2.2

MATLAB Windows

• MATLAB uses several different

windows to display data,

commands and results.

• They are not necessarily all open

at once

Page 17: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Command Window

Enter commands at the prompt

MATLAB Windows

Command History

Window

Records all commands issued in

the command window – including

mistakes

Current Directory

Window

Lists files stored in the

current directory

Workspace Window

Hidden behind the Current

Directory

Page 18: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Let’s look at the windows

one at a time

Page 19: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Command Window

• Similar to a scratch pad

• Once you hit enter, you can’t edit any

commands

• You can retype them or use the arrow

keys to retrieve commands and edit

them before hitting enter again

Command Window

Page 20: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Command History

• Records the commands you issue

in the command window

• When you exit the command

window, or when you issue the clc

command, the command window

is cleared

• But the command history remains

Command History

Page 21: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Command History

• You can transfer commands from the command history to the command window

• Double click on a command • It executes immediately

• Click and drag into the command window

• You can edit the command before executing

Page 22: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Workspace Window

Workspace Window

Page 23: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

When you define variables

in the command window,

they are listed in the

workspace window

Page 24: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Scalar

Vector

2-D

Matrix

Page 25: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Current Directory

• The current directory window is a

list of files

• When you try to load information

from a file or try to save

information – MATLAB uses the

current directory

Page 26: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Document Window

• If you double click on any variable

in the workspace window MATLAB

launches a document window

containing the array editor

• You can edit variables in the array

editor

Page 27: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Document Window

Page 28: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Figure Window

• When Figures are created a new

window opens

• It’s extremely easy to create

graphs in MATLAB

Page 29: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Note: The semicolon

suppresses the output from

each command

First create a vector of x

values – then a

corresponding vector of

y values

Page 30: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Matlab makes it easy to modify

graphs by adding

•Titles

•Axis labels

•Legends

•Other types of annotations

Page 31: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Editing Window

• This window allows you to type

and save a series of commands

without executing them

• There are several ways to open an

editing window

• From the file menu

• With the new file icon

Page 32: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Open an editing window

from the file menu or with

the new file icon

Page 33: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

New file icon

Page 34: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Save and Run

Write your code in the editing window,

then run it using the Save and Run icon

Page 35: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Section 2.3

Solving Problems with MATLAB

• We’ve already solved some

simple problems

• We need to understand how

MATLAB works to solve more

complicated problems

Page 36: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Variables

• MATLAB allows you to assign a

value to a variable

• A=3

• Should be read as A is assigned a

value of 3

• Use the variables in subsequent

calculations

Page 37: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Naming Variables

• All names must start with a letter

• They may contain letters, numbers

and the underscore ( _ )

• Names are case sensitive

• There are certain keywords you

can’t use

Page 38: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Use the iskeyword function

for a list of keywords iskeyword

ans =

'break'

'case'

'catch'

'classdef'

'continue'

'else'

'elseif'

'end‘

'for'

'function'

'global'

'if'

'otherwise'

'parfor'

'persistent'

'return'

'switch'

'try'

'while'

Keywords are not acceptable variable names

Page 39: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

You can reassign function

names

• MATLAB will let you use built-in

function names as variables – but

it’s a really bad idea

• sin = 3 changes sin from a

function to a variable

name

Page 40: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Practice Exercise 2.2

Which of these names are allowed

in MATLAB?

• test

• Test

• if

• my-book

• my_book

• Thisisoneverylongnamebutisitstillallowed?

• 1stgroup

• group_one

• zzaAbc

• z34wAwy?12#

• sin

• log

x

x

x

x

x x

bad

idea

Page 41: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Matrices in MATLAB The basic data type

• Group of numbers arranged into

rows and columns

• Single Value (Scalar)

• Matrix with one row and one column

• Vector (One dimensional matrix)

• One row or one column

• Matrix (Two dimensional)

Page 42: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Scalar Calculations

• You can use MATLAB like you’d

use a calculator

>> 9 + 10

ans=19

Command

Prompt

Result

Page 43: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Assignment Operator

• To define a variable a we might

type

a=1+2

which should be read as:

“a is assigned a value of 1+2 “

Page 44: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

How is the assignment operator

different from an equality?

• In algebra the equation x=3+5 means that both sides are the same

• In computers when we say x=3+5 we are telling the machine to store the value on the right hand side of the equation in a memory location, and to name that location x

Page 45: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Is that really different?

• Yes!!!

• In algebra this is not a true statement

x=x+1

• In computers (assignment statements)

it means replace the value in the

memory location named x, with a new

value equal to x+1

Page 46: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Order of Operation

• Same as you’ve learned in math

class

• Same as your calculator

• Parentheses first

• Exponentiation

• Multiplication / division

• Addition / subtraction

Page 47: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Order of Operation

5*(3+6) = 45

5*3+6 = 21

White space does not matter!!!

5*3 + 6 = 21

Adding a space around + and – signs makes the

expression more readable

Page 48: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Parentheses

• Use only ( )

• { } and [ ] mean something

different

• MATLAB does not assume

operators

5 * (3+4) not 5(3+4)

Page 49: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Compute from left to right

5*6/6*5 = 25

5*6/(6*5) = 1

Page 50: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Here’s an example Find the surface area of a cylinder

)(222 2 hrrrhrSA

r = radius

r = 5

h = height

h = 10

π r2

π r2

2π r * h

Page 51: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Array Operations

• Using MATLAB as a glorified

calculator is OK, but its real

strength is in matrix manipulations

Page 52: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

To create a row vector, enclose a list of values

in brackets

Page 53: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

You may use either a space or a

comma as a “delimiter” in a row

vector

Page 54: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Use a semicolon as a delimiter to create a

new row

Page 55: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Use a semicolon as a delimiter to create a

new row

Page 56: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Hint: It’s easier to keep track of how many

values you’ve entered into a matrix, if you

enter each row on a separate line. The

semicolons are optional

Page 57: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Shortcuts

• While a complicated matrix might have

to be entered by hand, evenly spaced

matrices can be entered much more

readily. The command

b= 1:5

or the command

b = [1:5]

both return a row matrix

Page 58: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

The default increment is 1, but if you

want to use a different increment put

it between the first and final values

Page 59: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

To calculate spacing

between elements use…

• linspace

• logspace

Page 60: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Initial value in the

array

Final value in the

array

number of elements in

the array

Page 61: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Initial value in the

array expressed

as a power of 10

Final value in the

array expressed

as a power of 10

number of elements in

the array

Page 62: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

It is a common mistake to enter the

initial and final values into the

logspace command, instead of

entering the corresponding power of

10

Page 63: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Hint

• You can include mathematical

operations inside a matrix

definition statement.

• For example

a = [0: pi/10: pi]

Page 64: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Mixed calculations between

scalars and arrays

• Matrices can be used in many calculations with scalars

• There is no confusion when we perform addition and subtraction

• Multiplication and division are a little different

• In matrix mathematics the multiplication operator (*) has a very specific meaning

Page 65: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Page 66: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Addition between arrays is

performed on

corresponding elements

Page 67: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Multiplication between

arrays is performed on

corresponding elements if

the .* operator is used

Page 68: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

MATLAB interprets * to mean matrix

multiplication. The arrays a and b are

not the correct size for matrix

multiplication in this example

Page 69: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Array Operations

• Array multiplication .*

• Array division ./

• Array exponentiation .^

In each case the size of the arrays must match

Page 70: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

The matrix capability of MATLAB makes it

easy to do repetitive calculations

• For example, assume you have a

list of angles in degrees that you

would like to convert to radians.

• First put the values into a matrix.

• Perform the calculation

Page 71: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Page 72: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Either the * or the .* operator can be

used for this problem, because it is

composed of scalars and a single

matrix

The value of pi is built into MATLAB as

a floating point number, called pi

Page 73: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

More about pi

• Because pi is an irrational number, it

can not be expressed exactly with a

floating point representation

• The MATLAB constant, pi, is really

an approximation.

• If you find sin(pi) MATLAB returns a

very small number.

Page 74: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Transpose

• The transpose operator changes

rows to columns or vice versa.

Page 75: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

The transpose operator

makes it easy to create

tables

Page 76: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

table =[degrees;radians]’ would have given

the same result

Page 77: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

The transpose

operator works on

both one dimensional

and two dimensional

arrays

Page 78: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Number Display

• Scientific Notation

• Although you can enter any number in

decimal notation, it isn’t always the best

way to represent very large or very small

numbers

• In MATLAB, values in scientific notation

are designated with an e between the

decimal number and exponent. (Your

calculator probably uses similar notation.)

Page 79: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

It is important to omit blanks between

the decimal number and the exponent.

For example, MATLAB will interpret

6.022 e23

as two values (6.022 and 1023 )

Page 80: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Display Format

• Multiple display formats are available

• No matter what display format you

choose, MATLAB uses double

precision floating point numbers in its

calculations

• MATLAB handles both integers and

decimal numbers as floating point

numbers

Page 81: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Default

• The default format is called short

• If an integer is entered it is

displayed without trailing zeros

• If a floating point number is

entered four decimal digits are

displayed

Page 82: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Other formats

• Changing the format affects all

subsequent displays

• format long results in 14 decimal

digits

• format bank results in 2 decimal

digits

• format short returns the display to

the default 4 decimal digits

Page 83: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Really Big and Really Small

• When numbers become too large or

too small for MATLAB to display using

the default format, it automatically

expresses them in scientific notation

• You can force scientific notation with

• format short e

• format long e

Page 84: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Common Scale Factor

• For long and short formats, a

common scale factor is applied to

the entire matrix if some of the

elements become very large, or

very small. This scale factor is

printed along with the scaled

values.

Page 85: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Common Scale

Factor

Page 86: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Two other formats

• format +

• format rat

Page 87: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Spacing in the command

window

• The format command also allows us to control how tightly information is spaced in the command window

• format compact

• format loose – (default)

• Most of the examples in this presentation use format compact

Notice that the value of A is still

being displayed using the rat

format, because we haven’t

changed it back to format short

Page 88: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Section 2.4

Saving Your Work

• If you save a MATLAB session

performed in the command

window, all that is saved are the

values of the variables you have

named

Page 89: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Variables are saved, not the commands in the command window

Page 90: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Save either by using the file menu or...

Save with a command in the

command window

Page 91: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

MATLAB automatically

saves to a .mat file

• If you want to save to another

format, such as .dat, you need to

explicitly tell the program

save <file_name> <variable_list> -ascii

Again – Remember that the only things being saved are the

values stored in the workspace window – not the commands

from the command window

Page 92: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Script M-files

• If you want to save your work,

(the commands you entered)

you need to create an M-file

• File->New->M-file

• Type your commands in the edit

window that opens

Page 93: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Page 94: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

• The file can be saved into the

current directory

• It runs in the command window

Page 95: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Save the file using

the save icon, or the

file menu

Page 96: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

You can dock the editing

window with the

MATLAB desktop, by

using the docking arrow

Page 97: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

This arrangement is

often easier to use

Page 98: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

I saved this file as

example.m

Notice that it now appears

in the current directory

When I

execute the

file, the figure

appears on

top of the

MATLAB

desktop

Page 99: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

The figure window

can also be docked

onto the MATLAB

desktop, using the

docking arrow

Page 100: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Notice that the command history

window is hidden underneath the

figure, but can be accessed with

the tab

Page 101: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Comments

The % sign identifies comments

You need one on each line

Page 102: 100 About MATLABstaff.iium.edu.my/.../ECE1322_Matlab1.pdf · 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-5-4.5-4-3.5-3-2.5-2-1.5-1-0.5 0 Rate of Change time, hour r Objectives After studying

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.

100 200 300 400 500

100

200

300

400

500

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

Rate of Change

time, hour

Ra

te o

f te

mp

era

ture

ch

an

ge

, d

eg

ree

s/h

ou

r

Summary

• Introduced the MATLAB Windows

• Basic matrix definition

• Save and retrieve MATLAB data

• Create and use script M-files