introduction to matlab damon tomlin february 22, 2008 lecture 3: data visualization & user...
TRANSCRIPT
![Page 1: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/1.jpg)
Introduction to MATLABIntroduction to MATLAB
Damon TomlinDamon TomlinFebruary 22, 2008February 22, 2008
Lecture 3: Data Visualization & User Interfaces
![Page 2: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/2.jpg)
A quick word about SPM . . .A quick word about SPM . . .
This can be a little intimidating . . .This can be a little intimidating . . .
![Page 3: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/3.jpg)
“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
![Page 4: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/4.jpg)
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.
![Page 5: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/5.jpg)
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
![Page 6: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/6.jpg)
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
![Page 7: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/7.jpg)
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-’);
![Page 8: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/8.jpg)
ImagesImages
imagescimagesc– PseudocolorPseudocolor– ColormapsColormaps
imageimage– M x N x 3 matrixM x N x 3 matrix
![Page 9: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/9.jpg)
HistogramsHistograms
histhist– designate binsdesignate bins
barbar– generic bar graphgeneric bar graph
![Page 10: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/10.jpg)
3D Visualization3D Visualization
Surface plotsSurface plots– ColorColor– TransparencyTransparency
Mesh plotsMesh plots
3D shapes3D shapes
![Page 11: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/11.jpg)
Making Visualizations More Making Visualizations More InformativeInformative
xlabel, ylabel, zlabelxlabel, ylabel, zlabel
titletitle
legendlegend
![Page 12: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/12.jpg)
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’)
![Page 13: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/13.jpg)
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
![Page 14: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/14.jpg)
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
![Page 15: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/16.jpg)
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;’]);
![Page 17: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/17.jpg)
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.
![Page 18: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/18.jpg)
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
![Page 19: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/19.jpg)
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
![Page 20: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/20.jpg)
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
![Page 21: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/21.jpg)
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
![Page 22: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/22.jpg)
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
![Page 23: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/23.jpg)
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
![Page 24: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/24.jpg)
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
![Page 25: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/25.jpg)
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
![Page 26: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/26.jpg)
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
![Page 27: Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649eec5503460f94bfd46d/html5/thumbnails/27.jpg)
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.