matlab for engineers 4e, by holly moore. © 2014 pearson education, inc., upper saddle river, nj....

41
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458. 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 R ate ofC hange tim e, hour Rate of tem perature change, degrees/hour Creating Graphical User Interfaces Chapter 15

Upload: gwendoline-cox

Post on 13-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval

system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Creating Graphical User Interfaces

Chapter 15

Page 2: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Objectives

After studying this chapter you should be able to:

• Understand how to use the GUIDE editor

• Understand how to modify function callbacks

• Be able to create graphical user interfaces

Page 3: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

GUI

• Graphical User Interface• GUIDE interface is a GUI to help

you create GUI’s• Review

• Structure Arrays• Subfunctions• Handle Graphics

Page 4: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

15.1 A Simple GUI with One User Interaction

• Create a GUI that allows us to enter the number of sides on a polygon – and that then draws the polygon in polar coordinates

Page 5: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Opening GUIDE

Page 6: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 7: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Design the GUI using the layout editor

Page 8: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Change the component palette display to a list

Page 9: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Component Palette

Page 10: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 11: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

To change the properties of an object, right click on it and then select ‘Property Inspector

Page 12: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 13: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Change the field from ‘Static Text’ to ‘Enter the

number of sides’

Page 14: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Adding code to the m-fileOnce you have created a layout in the editor, select the save and run icon to create the m-file

Page 15: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Selecting the ‘Show functions’ icon opens a list of all the subfunctions in the file

The only functions the user should modify are labeled as:

• gui_name_OpeningFcn

• graphics_object_name_Callback

Page 16: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Right click on the edit textbox to locate the corresponding m-file subfunction

Alternate Approach

Page 17: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Contents of the edit1_Callback

There is effectively no content, until you add some!

Page 18: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Modified edit1_Callback

This code retrieves the number of sides from the edit 1 window, then uses sides to calculate angles – and then to plot the polygon

Page 19: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Opening Appearance of the GUI

Appearance after requesting a 3 sided polygon, and running the m-file as modified with the code on the previous slide

Page 20: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Modify the Opening Function

• Rather than opening with a square axis, it would be nice if the GUI started with a blank graph laid out in polar coordinates

• This is accomplished by modifying the opening funciton

Page 21: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Modified Appearance of the opening GUI

Page 22: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

15.2 GUI with multiple user interactions

• Plot the trajectory of a projectile launched from a cannon

0

210 2

* cos( )

* sin( )

h t V

v t V gt

Page 23: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Ready Aim Fire Components

• Axes (for the graph)• Edit Textbox (for the angle input)• Edit Textbox (for the initial velocity input)• Push Button (to fire the cannon)• Static Textbox (To label the angle textbox• Static Textbox (to label the velocity textbox)• Panel (to group the textboxes together – not

necessary but nice)

Page 24: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Ready Aim Fire

Page 25: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Change to launch angle

Change the object names to something meaningful – so that it is

easier to navigate the code

Page 26: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 27: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

15.3 An Improved Ready_Aim_Fire Program

Page 28: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

15.4 A Much Better Ready_Aim_Fire Program

Page 29: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

The ‘Slider’ Property Inspector

Page 30: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 31: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

This static textbox is used to create a space for a message from MATLAB

Page 32: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Change the string property to a blank

Change the tag property to a meaningful name

Page 33: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 34: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

15.5 Built-in GUI Templates

Page 35: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 36: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Page 37: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

GUI with Axes and Menu

Page 38: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

This example GUI includes all the graphics objects available from GUIDE

Page 39: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Summary

• The GUIDE editor makes it easy to create graphical user interfaces in MATLAB

• To use GUIDE you need a basic understanding of:• Subfunctions• Handle graphics• Structure arrays

Page 40: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Summary

• Graphics objects are positioned on the editor

• Properties are modified with the property inspector

• M-file is created automatically, but must be modified to add content

Page 41: MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to:

Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

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

Rat

e of

tem

pera

ture

cha

nge,

deg

rees

/hou

r

Summary

• GUIDE includes three sample templates

• Other examples are found in HELP

• Demonstration video can also be found in HELP