Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User...

Preview:

Citation preview

Introduction to MATLABIntroduction to MATLAB

Damon TomlinDamon TomlinFebruary 22, 2008February 22, 2008

Lecture 3: Data Visualization & User Interfaces

A quick word about SPM . . .A quick word about SPM . . .

This can be a little intimidating . . .This can be a little intimidating . . .

“Any sufficiently advanced technology is indistinguishable from magic.”

SPM is three things:– Some functions that work on numbers (your data)

– Some functions that display the crunched numbers

– A bunch of buttons that run the functions when you press them

-- Arthur C. Clarke, possibly describing SPM

Overview of MATLAB GraphicsOverview of MATLAB Graphics

FiguresFigures

AxesAxes

UI ObjectsUI Objects

HandlesHandles– If you can see it, it has a handle.If you can see it, it has a handle.– Some things you can’t see have handles, too.Some things you can’t see have handles, too.– Use handles to manipulate properties.Use handles to manipulate properties.

Handles & PropertiesHandles & Properties

Figures, axes, and Figures, axes, and graphics have handles, graphics have handles, just like filesjust like files

These objects have These objects have propertiesproperties

These properties can be These properties can be alteredaltered

How many ways can we look at data?How many ways can we look at data?

2D line plots2D line plots

Pseudocolor ImagesPseudocolor Images

HistogramsHistograms

3D shapes3D shapes

2D Plots2D Plots

plot(x,y);plot(x,y);

plot([x1 x2 x3],[y1 y2 y3]);plot([x1 x2 x3],[y1 y2 y3]);

plot(x1,y1,’r.’,x2,y2,’b-’);plot(x1,y1,’r.’,x2,y2,’b-’);

ImagesImages

imagescimagesc– PseudocolorPseudocolor– ColormapsColormaps

imageimage– M x N x 3 matrixM x N x 3 matrix

HistogramsHistograms

histhist– designate binsdesignate bins

barbar– generic bar graphgeneric bar graph

3D Visualization3D Visualization

Surface plotsSurface plots– ColorColor– TransparencyTransparency

Mesh plotsMesh plots

3D shapes3D shapes

Making Visualizations More Making Visualizations More InformativeInformative

xlabel, ylabel, zlabelxlabel, ylabel, zlabel

titletitle

legendlegend

Other handy functionsOther handy functions

subplot(rows,columns,number)subplot(rows,columns,number)

Axis([xmin xmax ymin max])Axis([xmin xmax ymin max])

set(handle,’PropertyName’,value, . . .);set(handle,’PropertyName’,value, . . .);

get(handle,’PropertyName’)get(handle,’PropertyName’)

What’s a Graphical User Interface? What’s a Graphical User Interface? (GUI)(GUI)

Figure windowsFigure windows

Buttons, menus, sliders, etc.Buttons, menus, sliders, etc.

Appearance changes depending on inputs & outputsAppearance changes depending on inputs & outputs

Eliminates command line typingEliminates command line typing

Demystifying GUI’sDemystifying GUI’s

Interface objects have propertiesInterface objects have properties– Style – type of objectStyle – type of object– String – text associated with objectString – text associated with object– Callback – what the object doesCallback – what the object does– Value – current value of objectValue – current value of object

What these properties mean depends on What these properties mean depends on the type (Style) of object createdthe type (Style) of object created

UI Styles: ButtonsUI Styles: Buttons

Buttons cause commands Buttons cause commands to be executedto be executed

Style – pushbuttonStyle – pushbutton

String – text on the buttonString – text on the button

Callback – string Callback – string containing command(s) containing command(s) executed by buttonexecuted by button

Value – not importantValue – not important

The Eval FunctionThe Eval Function

Executes a string as though it were a Executes a string as though it were a command typed into a command window command typed into a command window or functionor function

Example 1: eval(‘disp(a);’);Example 1: eval(‘disp(a);’);

Example 2: eval([‘save ‘ FileName ‘ a b;’]);Example 2: eval([‘save ‘ FileName ‘ a b;’]);

Callbacks and EvalCallbacks and Eval

Callbacks are assigned Callbacks are assigned withinwithin functions functions

Callbacks are executed Callbacks are executed outsideoutside functions functions– (usually)(usually)

Therefore, any variables a callback needs Therefore, any variables a callback needs have to be stored somehow.have to be stored somehow.

UI Styles: Radio ButtonsUI Styles: Radio Buttons

Style – radiobuttonStyle – radiobutton

String – text on the buttonString – text on the button

Value – whether button is Value – whether button is pushed in or outpushed in or out

Callback – exclusivity code & Callback – exclusivity code & additional functionsadditional functions

Used in sets for mutually Used in sets for mutually exclusive, boolean optionsexclusive, boolean options

UI Styles: Check BoxesUI Styles: Check Boxes

Style – checkboxStyle – checkbox

String – text on the boxString – text on the box

Value – whether button is Value – whether button is checkedchecked

Callback – often nothing, Callback – often nothing, unless switching the option’s unless switching the option’s value executes a functionvalue executes a function

Used for boolean optionsUsed for boolean options

UI Styles: Edit WindowsUI Styles: Edit Windows

Style – editStyle – edit

String – text in the boxString – text in the box

Value – not usedValue – not used

Callback – function executed Callback – function executed when Enter key is pressedwhen Enter key is pressed

Used for typed inputs of names Used for typed inputs of names & values& values

UI Styles: Slider BarsUI Styles: Slider Bars

Style – sliderStyle – slider

String – not usedString – not used

Value – position of slider – Value – position of slider – between Max and Minbetween Max and Min

Callback – function executed Callback – function executed when slider is movedwhen slider is moved

Used when a variable can take Used when a variable can take on a spectrum of valueson a spectrum of values

UI Styles: Text BoxesUI Styles: Text Boxes

Style – textStyle – text

String – text in the boxString – text in the box

Value – not usedValue – not used

Callback – not usedCallback – not used

Used for displaying information, Used for displaying information, entitling portions of a GUIentitling portions of a GUI

UI Styles: FramesUI Styles: Frames

Style – FrameStyle – Frame

String – not usedString – not used

Value – not usedValue – not used

Callback – not usedCallback – not used

Used for grouping other Used for grouping other objects visuallyobjects visually

UI Styles: List BoxesUI Styles: List Boxes

Style – listboxStyle – listbox

String – cell array of each String – cell array of each possible choicepossible choice

Value – currently highlighted Value – currently highlighted selectionselection

Callback – function executed Callback – function executed when an item is selectedwhen an item is selected

Used for selecting options Used for selecting options when their names and numbers when their names and numbers may changemay change

UI Styles: Pop Up MenusUI Styles: Pop Up Menus

Style – popupmenuStyle – popupmenu

String – cell array of each String – cell array of each possible choicepossible choice

Value – currently selected Value – currently selected optionoption

Callback – function executed Callback – function executed when an item is selectedwhen an item is selected

Used for selecting options in a Used for selecting options in a more compact mannermore compact manner

Useful FunctionsUseful Functions

set – change something’s propertiesset – change something’s properties

get – find out what something’s propertiesget – find out what something’s properties

guidata – attach data to/pull data from GUIguidata – attach data to/pull data from GUI

SummarySummary

MATLAB has lots of functions to help you MATLAB has lots of functions to help you look at your datalook at your data

You can connect functions to GUI’s so you You can connect functions to GUI’s so you don’t have to type as muchdon’t have to type as much

As we’ll see, this is exactly what SPM As we’ll see, this is exactly what SPM does.does.