Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
© 2
009
The
Mat
hWor
ks, I
nc.
® ®
Scuola di Calcolo Scientifico con MATLAB
Palermo & Catania, Jan 27-29
2
® ®
Agenda
� Visualizing data
� How to build GUIs using MATLAB and GUIDE
� The GUI M-file(s)
� Working with user interface controls
� Callback programming and various advanced topics
� Development/Deployment Process Overview
� Deploying with MATLAB
3
® ®
Conveying Information
1970 1975 1980 1985 1990 1995 2000 2005 20100
2
4
6
8
10
12
14
1970 1975 1980 1985 1990 1995 2000 20050
5
10
15
20
25
year
num
ber
of h
urric
anes
TS1
2
3
45
longitude
latit
ude
Hurricane paths for 2004
-100 -80 -60 -40 -20 00
10
20
30
40
50
60
-100 -80 -60 -40 -20 0 200
10
20
30
40
50
60
70
800
1000
1200
1400
1600
S&
P 5
00
S&P500 high
01/04 01/05 01/06 01/07 01/08 01/092500
3000
3500
4000
4500
date
NZ
SE
50
7.32 7.322 7.324 7.326 7.328 7.33 7.332 7.334 7.336 7.338
x 105
2500
3000
3500
4000
4500
7.1 7.15 7.2 7.25 7.3 7.35
x 105
0
500
1000
1500
2000
4
® ®
1%2%< 1%< 1%2%< 1%< 1%< 1%2%< 1%< 1%1%< 1%< 1%
2%< 1%< 1%< 1%
1%< 1%1%
< 1%< 1%< 1%< 1%
2%< 1%
1%< 1%< 1%
2%1%
2%2%
1%3%
1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%
2%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%
< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%< 1%
1 2 3 4 5 6
5
10
15
20
25
30
35
0 2 40 2 40 2 40 2 40 5 100 10 200
2
4024
0
2
40
2
40
5
100
10
20
1970 1975 1980 1985 1990 1995 2000 2005 20100
2
4
6
8
10
12
14
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
5
10
15
20
25
30
35
1970 1975 1980 1985 1990 1995 2000 20050
5
10
15
20
25
30
0
2
4
6
8 010
2030
40
0
2
4
6
8
10
12
14
1970 1975 1980 1985 1990 1995 2000 20050
5
10
15
20
25
year
num
ber
of h
urric
anes
TS1
2
3
45
Plot Catalog
5
® ®
Estimate Electricity Usage
plot contourf ribbon
Filename: january.txt
6
® ®
-0.5 0 0.5 1 1.5 2 2.5-1
-0.5
0
0.5
1
1.5
horizontal displacement (x) [cubits]
��������
☯��
� � �
This graph is seriously annotated!3 ≤ ω < π
� � ���
����������
�
local maximum
global maximum
penguins
sloths(as t → ∞)
Annotation
ylabel
xlabel
textgtext
title
legend
grid
7
® ®
Customizing Axes
8
® ®
Handle Graphics ®
figure
axes
plot objects
(text/line/patch/etc)
9
® ®
Property Inspector and Browser
10
® ®
Get and Set
>> [c,ch] = contour(data,10);>> set(ch,'LineWidth',1.5)
11
® ®
Navigating the Hierarchy
>> h1 = get(gca,'Parent')>> h2 = get(gca,'Children')>> set(h2,'LineStyle', ':‘)
12
® ®
ExerciseBarc(y,label) draws the column of the 1-by-M y in different colors and labels the axes with custom te xt.
label is a 1-by-M cell array of strings.
label = …{'car','trucks','freight','barges','rail',planes'};
Y = [8 9 10 7 6 5]
13
® ®
guide
14
® ®
sommatore
edit
text
15
® ®
16
® ®
Interface Challenges
� Who are your users?� Predictability� Feedback and error control� Undo capabilities� Disable irrelevant options
17
® ®
Design Principles
Consistency Alignment Integrity
Harmony
Simplicity Unity Clarity
Elegance Directness
Familiarity Friendliness
Comfort Charm
18
® ®
Dynamic Interfaces
ContinuousPhysical
Smooth
ImmediateSnappy
Direct
19
® ®
Design Process
20
® ®
Resources
� http://www.math.duke.edu/education/ccp/resources/write/design
� http://www.fgcu.edu/onlinedesign/index.html
� http://cfg.cit.cornell.edu/design/contents.html
21
® ®
Earth-Quake Data Analysis
� Scenario:– Develop a tool to analyze earthquake
data
� Requirements:– Statistics capabilities
– Signal Processing Algorithms
– Automated program
– User interface
– Reporting capability
22
® ®
Data Analysis with MATLAB
Earth-Quake Data Analysis
quake.csv
23
® ®
Earth-Quake Analysis
Step1: Import and Visualize Data
� Import data from quake.xls file
� Scale the data
� Plot data� Customize and annotate data
� Save your work
24
® ®
Earth-Quake Analysis
Step1: Import Data
1. Move to your working directory using the Current Directory Browser.
2. Use the Import Wizard to load the data in quake.xls into a 10001 x 3 array data in the MATLAB Workspace.
3. In the Workspace Browser, select data . Use the Plot Selection menu at the top of the Workspace Browser to plot data .
4. Scale data by the gravitational acceleration g = 9.8 m/s^2. Please consider that data unit is cm/s^2.
5. Create a variable t for the time history.
6. In the Workspace Browser, select data and t . Use the Plot Selection menu at the top of the Workspace Browser to plot them
7. Enable Plot Tools with button on Figure Toolbar. Enhance the plot by adding titles and axis labels, changing fonts and colors, adjusting axes and plot properties.
8. Save your work to a MATLAB figure (quake.fig ) file in your working directory and save your variables to a mat-file (step1.mat )
25
® ®
Earth-Quake Analysis
Step2: Prepare Data
� Remove/replace missing values
� Smooth and detrend data
� Visualize original and processed data
� Write custom script to automate workflow
� Interactively explore data
26
® ®
Earth-Quake Analysis
Step2: Prepare Data
1. Open data in the Array Editor. Create a 10001 x 1 array e from the 1st column of data , and a 10001 x 1 array n from the 2nd one.
2. In the Workspace Browser, select e and t . Use the Plot Selection menu at the top of the Workspace Browser to plot e.
3. Enable Plot Tools with button on Figure Toolbar. Click 2D Axes in the New Subplot panel of the Figure Palette. Once the axes appears, the Add Data button on the Plot Browser is activated. Click this button to visualize n.
4. Use the Data Statistics Tool to find the mean acceleration in the East-West and North-South directions
5. Interactively zoom to explore e in the range [21 22.5]s
6. Use the MATLAB function isnan to identify missing values in e, and then remove them: � Replace missing values from “long term average” value� Interpolate missing values from neighboring value
t
27
® ®
Earth-Quake Analysis
Step2: Prepare Data
7. Search a MATLAB function for removing linear trends. Hint: docsearch('removing linear trend')
8. Write a custom script to automate workflow:– Create M-file from selected commands in Command History– Use a for loop to identify and interpolate missing values in data– Save the M-file as preProcess.m
28
® ®
Earth-Quake Analysis
Step3: Analyze Data
� Sharing Results from MATLAB– Publish m-file scripts– Export data and graphics
� Analyze the frequency content of your data
� Denoise/filter data
� Interactively locate the earthquake
29
® ®
Earth-Quake Analysis
Step3: Analyze Data
1. Using the fft command perform the Fast Fourier Transform of detrend_data and evaluate its power spectrum Pyy .
2. Use filter for denoising your signal. Apply a band-pass filter to eliminate frequency above and below the range [2-14]Hz.
3. Use cumsumto integrate filteredData and return the approximate x, y, and z coordinates of the seismometer during the earthquake. Write a custom function seisTraj.m to automate the integration.
4. Use print to save the 3-D plot (plot3 ) of the seismometer’s trajectory to a bmp file (e.g. sies.bmp ).
5. Visualize filteredData in three different subplots. Use ginput to measure the S-P time interval. The S-P time interval will be used to determine the distance the waves have traveled from the origin to the station.
30
® ®
Earth-Quake Analysis
Step4: Building an Application
� Convert script to reusable function– Code quality– Performance
� Add a graphical user interface– Use pre-defined dialog boxes
(select files, print graphics, …)– Develop a complete custom graphical user interface
31
® ®
Earth-Quake Analysis
Step4: Building an Application
1. Converting the following script m-Files to function m-Files – preProcess.m– preFilter.m– seistraj.m
2. At the MATLAB prompt run guide('seis.fig') . Look for a
subfunction that is named PSMenu_Callback and perform all
TODOstatements. Test if your application works.
4. Compile your application with the following command: deploytool
32
® ®
MATLABBuilder for .NET
MATLABBuilder for Excel
MATLABBuilder for
Java
.exe .dll/.lib .NETCOMExcelAdd-in
MATLAB Compiler
Java
Deploying Applications with MATLAB
www
33
® ®
MATLABMATLAB
DesktopDesktop
EndEnd--UserUser
MachineMachine
Working with MATLAB Compiler
1
2
3
© 2
009
The
Mat
hWor
ks, I
nc.
® ®
Questions?