天天看點

MATLAB中GUI界面彈出菜單的使用,Matlab GUIDE使用說明(Matlab GUI界面)

去年做了一些關于Matlab GUI的程式,現在又要做相關的東西,回想起來,當時很多經驗沒有記錄下來,現在回顧起來始終覺得不爽,是以從現在開始,一定要勤寫記錄。

從簡單的例子說起吧。

建立Matlab GUI界面通常有兩種方式:

1,使用.m檔案直接動态添加控件

2.使用GUIDE快速的生成GUI界面

顯然第二種可視化編輯方法算更适合寫大型程式。

一:建立GUI

1.在.m檔案中動态添加

例如

h_main=figure(‘name’,‘a demo of gui design’,‘menubar’,‘none’,…

'numbertitle','off','position',[100100300100]);

h_edit=uicontrol('style','edit','backgroundcolor',[111],'position',[20205020],...

'tag','myedit','string','1','horizontalalignment','left');

h_but1=uicontrol('style','pushbutton','position',[20505020],'string','INC',...

'callback',['v=eval(get(h_edit,''string''));',...

'set(h_edit,''string'',int2str(v+1));']);

h_but2=uicontrol('style','pushbutton','position',[80505020],'string','DEC',...

'callback',['v=eval(get(h_edit,''string''));','set(h_edit,''string'',int2str(v-1));']);

2.使用GUIDE幫助建立GUI

在Command裡面輸入GUIDE或者從菜單裡面,或者從快捷按鈕均可進入GUIDE