GUI設(shè)計小程序代碼_第1頁
GUI設(shè)計小程序代碼_第2頁
GUI設(shè)計小程序代碼_第3頁
GUI設(shè)計小程序代碼_第4頁
GUI設(shè)計小程序代碼_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、matlab GUI設(shè)計  能產(chǎn)生正弦信號、方波、三角波源代碼如下:function varargout = Mytools(varargin)gui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, .                   'gui_

2、Singleton',  gui_Singleton, .                   'gui_OpeningFcn', Mytools_OpeningFcn, .                 

3、0; 'gui_OutputFcn',  Mytools_OutputFcn, .                   'gui_LayoutFcn',  , .                 &

4、#160; 'gui_Callback',   );if nargin & isstr(varargin1)    gui_State.gui_Callback = str2func(varargin1);endif nargout    varargout1:nargout = gui_mainfcn(gui_State, varargin:);else    gui_mainfcn(gui_State, varargin:);endfunction Myto

5、ols_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject;guidata(hObject, handles);function varargout = Mytools_OutputFcn(hObject, eventdata, handles)varargout1 = handles.output;function pushbutton1_Callback(hObject, eventdata, handles)t=0:0.001:6;y=sin(0.5*pi*t);plot(t,y);title

6、('正弦信號');grid on;axis(-0.5 6.2 -1.2 1.2);set(handles.text1,'String',' 說明:周期為4,幅值為2的正弦波信號');function edit2_CreateFcn(hObject, eventdata, handles)if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundC

7、olor',get(0,'defaultUicontrolBackgroundColor');endfunction pushbutton8_Callback(hObject, eventdata, handles)function pushbutton10_Callback(hObject, eventdata, handles)t=0:0.001:3;y=square(2*pi*t,50);plot(t,y);grid on;axis(0,3,-1.2,1.2);title('方波信號');set(handles.text1,'String&

8、#39;,' 說明:周期為1,幅值為2的方波信號');function pushbutton9_Callback(hObject, eventdata, handles)t=-6:0.01:6;ft=sawtooth(pi*t,0.5);plot(t,ft);grid on;title('三角波信號');axsi(-6 6 -1.2 1.2);set(handles.text1,'String',' 說明:周期為2,幅值為2的三角波信號');MATLAB實例默認(rèn)分類 2009-06-22 22:06:47 閱讀998 評論0 &#

9、160; 字號:大中小 訂閱         這個程序主要是一個遞推的最小二乘發(fā),根據(jù)diphon方程來辨識一類系統(tǒng)的參數(shù).        在matlab的comand窗口,輸入guide,就會彈出控件設(shè)計的工具,有button,text edit.可以通過屬性檢查器來改變一些屬性如果用過VB的人應(yīng)該知道怎么回事,點(diǎn)擊右鍵就可以看到了.主要是設(shè)計回調(diào)函數(shù),不同句柄的數(shù)據(jù)傳送,比較麻煩,而且發(fā)現(xiàn)BUG比較多.直接用命令的形式編程也可以,編

10、寫簡單的GUI到是很方便的.   在gui界面里可以輸入遺忘因子,迭代次數(shù),輸入函數(shù).源程序function varargout = lsmgui(varargin)% LSMGUI M-file for lsmgui.fig%      LSMGUI, by itself, creates a new LSMGUI or raises the existing%      singleton*.%      H = LSMG

11、UI returns the handle to a new LSMGUI or the handle to%      the existing singleton*.%      LSMGUI('CALLBACK',hObject,eventData,handles,.) calls the local%      function named CALLBACK in LSMGUI.M with the given input

12、 arguments.%      LSMGUI('Property','Value',.) creates a new LSMGUI or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before lsmgui_Openin

13、gFunction gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to lsmgui_OpeningFcn via varargin.%      *See GUI Options on GUIDE's Too

14、ls menu.  Choose "GUI allows only one%      instance to run (singleton)".% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help lsmgui% Last Modified by GUIDE v2.5 30-Nov-2006 23:59:34% Begin initialization code - DO NOT EDI

15、Tgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, .                   'gui_Singleton',  gui_Singleton, .      &#

16、160;            'gui_OpeningFcn', lsmgui_OpeningFcn, .                   'gui_OutputFcn',  lsmgui_OutputFcn, .    

17、               'gui_LayoutFcn',  , .                   'gui_Callback',   );if nargin & isstr(varargin1)&#

18、160;   gui_State.gui_Callback = str2func(varargin1);endif nargout    varargout1:nargout = gui_mainfcn(gui_State, varargin:);else    gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before lsmgui is made visible.func

19、tion lsmgui_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject    handle to figure% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUI

20、DATA)% varargin   command line arguments to lsmgui (see VARARGIN)% Choose default command line output for lsmguihandles.output = hObject;% Update handles structureguidata(hObject, handles);initialize_gui(hObject, handles);% UIWAIT makes lsmgui wait for user response (see UIRESUME)% uiwait(

21、handles.figure1);% - Outputs from this function are returned to the command line.function varargout =lsmgui_OutputFcn(hObject, eventdata, handles)% varargout  cell array for returning output args (see VARARGOUT);% hObject    handle to figure% eventdata  reserved - to be defi

22、ned in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout1 = handles.output;% - Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, event

23、data, handles)% hObject    handle to edit1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% 

24、;      See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');end function edit1_Callback(hObject, eventdata, ha

25、ndles)n= str2double(get(hObject, 'String');if isnan(n)             %輸入迭代次數(shù)    set(hObject, 'String', 0);    errordlg('Input must be a number','Error');enddata = getappdata(gcbf,

26、'metricdata');data.n = n;setappdata(gcbf, 'metricdata', data);% hObject    handle to edit1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObje

27、ct,'String') returns contents of edit1 as text%        str2double(get(hObject,'String') returns contents of edit1 as a double% - Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hOb

28、ject    handle to edit2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%    

29、   See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');end function edit2_Callback(hObject, eventdata, handles)a1 = str2doub

30、le(get(hObject, 'String');%輸入?yún)?shù)data = getappdata(gcbf, 'metricdata');data.a1 = a1;setappdata(gcbf, 'metricdata', data);% hObject    handle to edit2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    str

31、ucture with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text%        str2double(get(hObject,'String') returns contents of edit2 as a double% - Executes during object creation, after setting all prop

32、erties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit3 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usu

33、ally have a white background on Windows.%       See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');end 

34、function edit3_Callback(hObject, eventdata, handles)a2 = str2double(get(hObject, 'String');%輸入?yún)?shù)data = getappdata(gcbf, 'metricdata');data.a2 = a2;setappdata(gcbf, 'metricdata', data);% hObject    handle to edit3 (see GCBO)% eventdata  reserved - to be def

35、ined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text%        str2double(get(hObject,'String') returns contents of edit3 as a

36、double% - Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit4 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not c

37、reated until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColo

38、r',get(0,'defaultUicontrolBackgroundColor');end function edit4_Callback(hObject, eventdata, handles)b1= str2double(get(hObject,'String');%輸入?yún)?shù)data = getappdata(gcbf, 'metricdata');data.b1 = b1;setappdata(gcbf, 'metricdata', data);% hObject    h

39、andle to edit4 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit4 as text%        str2doubl

40、e(get(hObject,'String') returns contents of edit4 as a double% - Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit5 (see GCBO)% eventdata  reserved - to be defined in a future ver

41、sion of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','whi

42、te');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');end function edit5_Callback(hObject, eventdata, handles)b2 = str2double(get(hObject, 'String');%輸入?yún)?shù)data = getappdata(gcbf, 'metricdata');data.b2 = b2;setappdat

43、a(gcbf, 'metricdata', data);% hObject    handle to edit5 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of e

44、dit5 as text%        str2double(get(hObject,'String') returns contents of edit5 as a double% - Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit6 (se

45、e GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc

46、    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');end function edit6_Callback(hObject, eventdata, handles)i = str2double(get(hObject, 'String');if (i=0)&

47、#160;   set(hObject, 'String', 0);    errordlg('Input must not be   0','Error');    else     data = getappdata(gcbf, 'metricdata');    data.i = i;    setappdata(gcbf, 'm

48、etricdata', data);end% hObject    handle to edit6 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit6 as tex

49、t%        str2double(get(hObject,'String') returns contents of edit6 as a double% - Executes during object creation, after setting all properties.function edit7_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit7 (see GCBO)% ev

50、entdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc  

51、;  set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');end function edit7_Callback(hObject, eventdata, handles)f = str2double(get(hObject, 'String');if (f=1)|(f=2)|(f=3)

52、   data = getappdata(gcbf, 'metricdata');   data.f = f;   setappdata(gcbf, 'metricdata', data);else   set(hObject, 'String', 0);  errordlg('Input must be 1 or 2 or 3','Error'); end% hObject    ha

53、ndle to edit7 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit7 as text%        str2double

54、(get(hObject,'String') returns contents of edit7 as a double% - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)    data = getappdata(gcbf, 'metricdata');R=data.b1;data.b2 ;-1*data.a1 ;-1*data.a2;%已知參數(shù)k=0;%迭代次數(shù)pi=3.142;

55、W=0 0 0 0'%計算期望輸出用u1 u2 y3 y4P=1000 0 0 0;0 1000 0 0;0 0 1000 0;0 0 0 1000;%4*4的迭代矩陣初值取103105T=0 0 0 0'%要辨識的參數(shù)Z=0 0 0 0'%觀測的輸入輸出for k=1:data.n;%迭代次數(shù)Z=W;    Y(k)=R'*W;%K+1時刻的觀測值,系統(tǒng)輸出Q(k)=T'*Z;%估計的輸出E(k)=Y(k)-Q(k);%辨識誤差L=P*Z/(data.i+Z'*P*Z);%K(K+1)T=T+L*E(k);%一次參

56、數(shù)估計if data.i=0    errordlg('Input must be 1 or 2 or 3 ,default 1','Error');    data = getappdata(gcbf, 'metricdata');    data.i = 0.9;    setappdata(gcbf, 'metricdata', data);endP=1/data.i*(P-L*Z'*P);%P矩陣

57、迭代一次a(k)=T(1);b(k)=T(2);c(k)=T(3);d(k)=T(4);%a ,b,c,d記錄估計參數(shù)的變化,繪圖用if data.f = 2            %選擇輸入函數(shù)   u=5*sin(0.01*pi*k);%輸入函數(shù),進(jìn)行辨識用   elseif data.f = 1    u=3*sin(0.01*pi*k)*3*cos(0.5*pi*k);elseif data.f=3 

58、;  u=5*sin(0.01*pi*k)*0.2*5*sin(0.1*pi*k) ;else     errordlg('Input must be 1 or 2 or 3 ,default 1','Error');    data = getappdata(gcbf, 'metricdata');    data.f = 1;    setappdata(gcbf, 'metricdata', da

59、ta);    u=3*sin(0.01*pi*k)*3*cos(0.5*pi*k); end    W(2)=W(1);W(1)=u;W(4)=W(3);W(3)=Y(k);%W=u W(1) y W(3) Z(K+1)endk=1:data.n;%可以用axis(1,100,-1.2,1)來設(shè)定坐標(biāo)范圍figure;subplot(1,2,1),plot(k,a(k),'r'),xlabel('迭代次數(shù) n'),ylabel('估計參數(shù)'),title('參數(shù)的辨識'

60、),hold on;plot(k,b(k),'y'),plot(k,-c(k),'g'),plot(k,-d(k),text(1,-0.3,'綠色表示a1的估計值'),text(1,0,'藍(lán)色辨識a2的估計值'),text(1,0.3,'紅色表示b1的估計值'),text(1,0.6,'黃色表示b2的估計值'),hold offsubplot(1,2,2),plot(k,Y(k),xlabel('迭代次數(shù) n'),ylabel('系統(tǒng)輸出,輸出估計及誤差'),titl

61、e('輸出信息'),hold on;plot(k,Q(k),'y'),plot(k,E(k),'r'),text(1,0.3,'藍(lán)色表示系統(tǒng)輸出'),text(1,0,'黃色表示估計的輸出'),text(1,-0.3,'紅色表示誤差'),hold off% hObject    handle to pushbutton1 (see GCBO)% eventdata  reserved - to be defined in a future version of

62、 MATLAB% handles    structure with handles and user data (see GUIDATA)% - Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)initialize_gui(gcbf, handles);% hObject    handle to pushbutton2 (see GCBO)% eventdata  reser

63、ved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)function initialize_gui(fig_handle, handles)data.n=10; data.a1=-1;data.a2=0.632;data.b1=0.368;data.b2=0.264;data.i=0.9; data.f = 1; setappdata(fig_handle, 'met

64、ricdata', data);set(handles.edit1, 'String',data.n);set(handles.edit2, 'String', data.a1);set(handles.edit3, 'String', data.a2);set(handles.edit4, 'string', data.b1);set(handles.edit5, 'string', data.b2);set(handles.edit6, 'String',data.i);set(hand

65、les.edit7, 'String', data.f);        標(biāo)簽: 專業(yè)學(xué)習(xí)   . 收藏到我的網(wǎng)摘 引用通告 推薦 評論 舉報 打印 本文章被推薦到了0個圈子點(diǎn)擊數(shù): 2645  評論數(shù): 230我 頂 !覺得精彩就頂一下,頂?shù)亩嗔耍恼聦⒊霈F(xiàn)在更重要的位置上。 下一篇: 我喜歡的刀刀上一篇: 辯證法與放屁博客鏈  和訊相冊用戶調(diào)查,歡迎大家參加22日預(yù)測:資金涌入 銀行地產(chǎn)聯(lián)袂領(lǐng)漲訂閱財經(jīng)手機(jī)報,參與調(diào)查贏大獎 更多.每日18時專家在線解盤超短線操作技

66、巧培訓(xùn)迎牛年和訊送三重大禮楚河漢界春節(jié)大放送!獨(dú)家揭秘主力資金動向十大牛股引爆市場狂潮最新讀者留下足跡請登錄登錄注冊wawe1ni767匿名者(未注冊) Re: matlab的GUI編程 4/9/2008 10:19:43 PM一個命令按鈕,就是把這六個文本框輸入的數(shù)字組成的矩陣相乘 ,請問怎么用matlab UGI 里編程,我qq282121142,請加我,謝謝引用 支持 反對 刪除 不允許匿名評論  匿名者(未注冊) Re: matlab的GUI編程 5/11/2007 5:20:21 PM你好請問文件中的保存、退出的代碼怎么編寫?謝謝!急!引用 支持 反對 刪除 不允許匿名評論

67、  zqcumt發(fā)送私信 Re: matlab的GUI編程 4/25/2007 10:39:28 PM以下是引用 小5 急求! 于 2007-4-14 16:39:05 的發(fā)言:您好!我現(xiàn)在正在做gui的圖形界面設(shè)計的畢業(yè)設(shè)計,對里面的回調(diào)函數(shù)不是很清楚,不知道怎么編。還有很多問題想請教你,希望你多指點(diǎn)指點(diǎn)哈,能不能給我一份電子版的資料,謝了!可以的話請加我QQ372841578想和你進(jìn)一步學(xué)習(xí)哈。事情有點(diǎn)急哈請早點(diǎn)聯(lián)系我好嗎?我的油箱:limoshiwo163 關(guān)于回調(diào)函數(shù)我在博客里轉(zhuǎn)貼了別人的一些文章,可以看看應(yīng)該能夠很好的理解引用 支持 反對 刪除 加入黑名單  zq

68、cumt發(fā)送私信 Re: matlab的GUI編程 4/25/2007 10:35:32 PM最近比較忙,所以也沒時間來博客上看,對于朋友們的問題不能及時回復(fù)我推薦一本書吧。好像叫精通matlab的gui編程。網(wǎng)上可以下載到。我現(xiàn)在沒時間幫你編寫或者調(diào)試 程序,真是不好意思引用 支持 反對 刪除 加入黑名單  匿名者(未注冊) Re: matlab的GUI編程 4/23/2007 11:45:59 AMif strcmp(get(handles.run_wave,'String'),'RUN/PLOT')set(handles.run_wave,

69、9;String','STOP');cla;set(handles.display_plot,'HandleVisibility','On')set(handles.time_plot,'HandleVisibility','Off')cla; % clear figureset(gca,'UserData',1)pause(0.01)options = odeset('RelTol',1e-4,'AbsTol',1e-4 1e-4 1e-4);t1,Y =

70、ode45(lorenzequation,t0 tfinal,y0,options,b,r,sigma);t2,DY = ode45(lorenzequation,t0 tfinal,dy,options,b,r,sigma);ball_plot = line('XData',y(1),'YData',y(2),'ZData',y(3), .'Color','Blue','Marker','.','Markersize',25,'Erase','

71、;Xor');line_plot = line('XData','YData','YData','Color','Blue','LineStyle','-','Erase','None');ball_plotd = line('XData',dy(1),'YData',dy(2),'ZData',dy(3), .'Color','Red','Marker&#

72、39;,'.','Markersize',25,'Erase','Xor');line_plotd = line('XData','YData','YData','Color','Red','LineStyle','-','Erase','None');set(handles.display_plot,'Drawmode','Fast','Visible','On','NextPlot','Add')set(handles.display_plot,'HandleVisibility','Off')set(handles.time_plot,'HandleVis

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論