Top Banner
MATLAB 圖圖圖圖圖圖圖 圖圖圖圖圖圖 圖圖圖 2014/3/11
74

Matlab GUI

Aug 06, 2015

Download

Software

Juin-Der Lee
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Matlab GUI

MATLAB 圖形使用者介面

程式設計簡介李俊德

2014/3/11

Page 2: Matlab GUI

大綱

•範例 : Homework1_GUI

•The process of creating GUI

1. Designing the GUI

2. Laying out the GUI

3. Programming the GUI

Page 3: Matlab GUI

• 財務工程與金融創新( II )作業 01

Page 4: Matlab GUI

範例 : Homework1_GUI

Page 5: Matlab GUI

範例 : Homework1_GUI

• demo

Page 6: Matlab GUI

The process of creating GUI

1. Designing the GUI – design the GUI on paper

2. Laying out the GUI – placing the controls within the Layout Editor

3. Programming the GUI – writing the callbacks for the controls

Page 7: Matlab GUI

Step 1: Design the UI

Page 8: Matlab GUI

Step 1: Design the UI

Page 9: Matlab GUI

Step 2: Laying out the GUI

1. Creating the layout

2. Set the GUI figure size

3. Add the components

4. Align the objects

5. Set properties for each components – string, tag, callback

- The tag property is also used to name the callback function.

6. Activate the GUI – main.fig, main.m

Page 10: Matlab GUI

Step 2.1: Creating the layout

Page 11: Matlab GUI

Step 2.1: Creating the layout

Page 12: Matlab GUI

Component palette

GUIDE (GUI Development Environment)

Layout Area

Page 13: Matlab GUI

GUIDE Tools Summary

Page 14: Matlab GUI

• Layout Editor – Add and arrange objects in the figure window

• Alignment Tool – align objects with respect to each other.

• Property Inspector – inspect and set property values.

• Object Browser – observe a hierarchical list of the Handle Graphics objects.

• Menu Editor – create menus for the window menu bar and context menus for any component in your layout.

GUIDE Toolset

Page 15: Matlab GUI

Step 2.2: Set the GUI figure size

Page 16: Matlab GUI

Step 2.2: Set the GUI figure size

Page 17: Matlab GUI

Component palette

Step 2.3: Add the components

Page 18: Matlab GUI

Step 2.3: Add the components

Page 19: Matlab GUI

Step 2.3: Add the components

Page 20: Matlab GUI

Step 2.3: Add the components

Page 21: Matlab GUI

Step 2.3: Add the components

Page 22: Matlab GUI

Step 2.3: Add the components

Page 23: Matlab GUI

Step 2.3: Add the components

Page 24: Matlab GUI

Step 2.3: Add the components

• demo

Page 25: Matlab GUI

Step 2.3: Add the components

Page 26: Matlab GUI

Step 2.4: Align the objects

Page 27: Matlab GUI

Step 2.4: Align the objects

1. 用滑鼠全選2. 按 Align Objects

Page 28: Matlab GUI

Step 2.4: Align the objects

Vertical

Horizontal

Page 29: Matlab GUI

Step 2.4: Align the objects

左邊對齊

Page 30: Matlab GUI

Step 2.4: Align the objects

Page 31: Matlab GUI

Step 2.4: Align the objects - finish

Page 32: Matlab GUI

Step 2.5: Set properties for each components-Static Text

2. 按 Property Inspector

1. 點選一個 Static Text

Page 33: Matlab GUI

Step 2.5: Set properties for each components-Static Text

3. 出現 Property Inspector 視窗

Page 34: Matlab GUI

Step 2.5: Set properties for each components-Static Text

FontXX: 設定字型

Position: 設定位置、大小

String: 設定顯示文字

Tag: 設定標籤 ( 相當於學生名字 )

Page 35: Matlab GUI

Step 2.5: Set properties for each components-Static Text

Page 36: Matlab GUI

Step 2.5: Set properties for each components-Static Text

Page 37: Matlab GUI

Step 2.5: Set properties for each components-Pop-up Menu

Page 38: Matlab GUI

Step 2.5: Set properties for each components-Pop-up Menu

Page 39: Matlab GUI

Step 2.5: Set properties for each components-Pop-up Menu

Page 40: Matlab GUI

Step 2.5: Set properties for each components-Pop-up Menu

Page 41: Matlab GUI

Step 2.5: Set properties for each components-Pop-up Menu

Page 42: Matlab GUI

Step 2.5: Set properties for each components-Pop-up Menu

Page 43: Matlab GUI

Step 2.5: Set properties for each components-Edit Text

Page 44: Matlab GUI

Step 2.5: Set properties for each components-Edit Text

Page 45: Matlab GUI

Step 2.5: Set properties for each components-Edit Text

Page 46: Matlab GUI

Step 2.5: Set properties for each components-Edit Text

Page 47: Matlab GUI

Step 2.5: Set properties for each components-Edit Text

Page 48: Matlab GUI

Step 2.5: Set properties for each components-Push Button

Page 49: Matlab GUI

Step 2.5: Set properties for each components-Push Button

Page 50: Matlab GUI

Step 2.5: Set properties for each components-Push Button

Page 51: Matlab GUI

Step 2.5: Set properties for each components-Push Button

Page 52: Matlab GUI

Step 2.5: Set properties for each components-finish

Page 53: Matlab GUI

Step 2.6: Activate the GUI

Page 54: Matlab GUI

Step 2.6: Activate the GUI

Page 55: Matlab GUI

Step 3: Programming the GUI

The application M-file:

• Initializes and launches the GUI.

• Contains the callback functions for all components in the GUI.

Page 56: Matlab GUI

Windows Programming Concepts

• Event-driven (事件驅動 ) - mouse click, key stroke, button press

• Handle - each UI object has a ID number called handle.( 相當於學生學號 ) - get/set properties of a UI object through its ID number.

• Callback function - system call

caller: application callee: system

- callback function caller: systemcallee: application

Page 57: Matlab GUI

顧客去商店買橘子。

發現橘子沒貨了。

顧客隔一陣子再去看貨到了沒。

主動者 = 顧客,被動者 = 商店

Page 58: Matlab GUI

去商店買橘子。

店員在橘子到貨的時候通知顧客採取行動 ( 例 : 前來購買 ) 。

發現橘子沒貨了。

Callback

主動者 = 商店,被動者 = 顧客橘子到貨 = event商店通知顧客採取行動 ( 例 : 前來購買 ) = callback

Page 59: Matlab GUI

Procedure

發生事件系統呼叫相關 callback函式

取得相關元件資訊

修改相關元件資訊

KeyPressKeyReleaseButtonDownButtonUpResize…

Popupmenu 中的字串Edit 元件中的數值

計算

PremiumEdit 中的數值

呼叫作業一的相關函式

Page 60: Matlab GUI

1. 使用者選擇 Products 和Methods

2. 使用者輸入參數值

3. 使用者按下 Calculate 按鍵,發生 ButtonPress 事件4. 系統呼叫 main.m 中的 CalPushButton_CallBack() 函式5. CalPushButton_CallBack() 呼叫 calcluate() 函式6. calcluate() 函式根據 Product 和 Method 來呼叫作業一的相關函式( 例 :opp_cf.m) ,並將參數值傳入。

Page 61: Matlab GUI

7.opp_cf.m 計算完結果後, calcluate() 函式將結果顯示在 PremiumEdit中。

Page 62: Matlab GUI

4. 系統呼叫 main.m 中的 CalPushButton_CallBack() 函式

5. CalPushButton_CallBack() 呼叫 calcluate() 函式

呼叫 calculate()

使用者按下 Calculate 鍵後,系統呼叫CalPushButton_CallBack()函式

Page 63: Matlab GUI

取得 product and method

取得參數值

6. calcluate() 函式根據 Product 和 Method 來呼叫作業一的相關函式 ( 例 :opp_cf.m) ,並將參數值傳入。

Page 64: Matlab GUI

根據 product 和 method來決定要呼叫作業一的哪一個函式

執行作業一的函式

將結果顯示在PremiumEdit 中

7.opp_cf.m 計算完結果後, calcluate() 函式將結果顯示在PremiumEdit 中。

Page 65: Matlab GUI

根據 product 和 method 來決定要呼叫作業一的哪一個函式

Page 66: Matlab GUI

讀取元件的資訊

根據 tag 和 findobj() 來取得 ProductPopupmenu的 handle 值

根據 handle 值和 get() 取得 ProductPopupmenu 的字串

Page 67: Matlab GUI

修改元件的資訊

根據 tag 和 findobj() 來取得 PremiumEdit 的handle 值

根據 handle 值和 set() 修改PremiumEdit 中的數值字串

Page 68: Matlab GUI

Programming GUI

發生事件系統呼叫相關 callback函式

取得相關元件資訊

修改相關元件資訊

KeyPressKeyReleaseButtonDownButtonUpResize…

1.根據 tag 和 findobj()來取得元件的 handle值

2.根據 handle 值和 get()來讀取元件的資訊

計算

1.根據 tag 和 findobj()來取得元件的handle 值

2.根據 handle 值和set() 來設定元件的資訊

Page 69: Matlab GUI

Review

•The process of creating GUI

1. Designing the GUI

2. Laying out the GUI

GUIDE

Set properties

3. Programming the GUI

Event

Callback function

Tag, findobj(), handle, get(), set()

Page 70: Matlab GUI

For more information…

Page 71: Matlab GUI

Product Help

Page 72: Matlab GUI

入門介紹

Page 73: Matlab GUI

詳細介紹

Page 74: Matlab GUI

Thank you for your attention!