`
deepfuture
  • 浏览: 4411954 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80127
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:70342
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103582
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:286551
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:15054
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:67785
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32290
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:46075
社区版块
存档分类
最新评论

matlab-GUI程序(3)

 
阅读更多

在打开函数中,增加handles中的字段

function test1_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 GUIDATA)
% varargin   command line arguments to test1 (see VARARGIN)

% Choose default command line output for test1
handles.output = hObject;

% Update handles structure
handles.numa=1
handles.numb=1
handles.numc=1
guidata(hObject, handles);

% UIWAIT makes test1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

 

 

下面完成将结果赋值

> help guihandles
 GUIHANDLES Return a structure of handles.
    HANDLES = GUIHANDLES(H) returns a structure containing handles of
    objects in a figure, using their tags as fieldnames.  Objects
    are excluded if their tags are empty, or are not legal variable
    names.  If several objects have the same tag, that field in the
    structure contains a vector of handles.  Objects with hidden
    handles are included in the structure.
 
    H is a handle that identifies the figure - it can be the figure
    itself, or any object contained in the figure.
 
    HANDLES = GUIHANDLES returns a structure of handles for the
    current figure.
 
    Example:
 
    Suppose an application creates a figure with handle F, containing
    a slider and an editable text uicontrol whose tags are 'valueSlider'
    and 'valueEdit' respectively.  The following excerpts from the
    application's M-file illustrate the use of GUIHANDLES in callbacks:
 
    ... excerpt from the GUI setup code ...
 
    f = figure;
    uicontrol('Style','slider','Tag','valueSlider', ...);
    uicontrol('Style','edit','Tag','valueEdit',...);
 
    ... excerpt from the slider's callback ...
 
    handles = guihandles(gcbo); % generate handles struct
    set(handles.valueEdit, 'string',...
        num2str(get(handles.valueSlider, 'value')));
 
    ... excerpt from the edit's callback ...
 
    handles = guihandles(gcbo);
    val = str2double(get(handles.valueEdit,'String'));
    if isnumeric(val) & length(val)==1 & ...
       val >= get(handles.valueSlider, 'Min') & ...
       val <= get(handles.valueSlider, 'Max')
      % update the slider's value if the edit's value is OK:
      set(handles.valueSlider, 'Value', val);
    else
      % flush the bad string out of the edit; replace with slider's
      % current value:
      set(handles.valueEdit, 'String',...
        num2str(get(handles.valueSlider, 'Value')));
    end
 
    Note that in this example, the structure of handles is created
    each time a callback executes.  See the GUIDATA help for an
    example in which the structure is created only once, and cached
    for subsequent use.

=================

matlab的一元高次方程数值解

 

 

 

 



 

 

计算结果的程序为:

function btn_draw_Callback(hObject, eventdata, handles)
% hObject    handle to btn_draw (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%求解一元二次方程
myres=roots([handles.numa,handles.numb,handles.numc]);
set(handles.result,'string',mat2str(myres)) ;

 完整程序为

function varargout = test1(varargin)
% TEST1 M-file for test1.fig
%      TEST1, by itself, creates a new TEST1 or raises the existing
%      singleton*.
%
%      H = TEST1 returns the handle to a new TEST1 or the handle to
%      the existing singleton*.
%
%      TEST1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TEST1.M with the given input arguments.
%
%      TEST1('Property','Value',...) creates a new TEST1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before test1_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to test1_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools 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 test1
                                            
% Last Modified by GUIDE v2.5 04-Oct-2012 17:21:13

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @test1_OpeningFcn, ...
                   'gui_OutputFcn',  @test1_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before test1 is made visible.
function test1_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 GUIDATA)
% varargin   command line arguments to test1 (see VARARGIN)

% Choose default command line output for test1
handles.output = hObject;

% Update handles structure
handles.numa=1
handles.numb=1
handles.numc=1
guidata(hObject, handles);

% UIWAIT makes test1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = test1_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in btn_draw.
function btn_draw_Callback(hObject, eventdata, handles)
% hObject    handle to btn_draw (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%求解一元二次方程
myres=roots([handles.numa,handles.numb,handles.numc]);
set(handles.result,'string',mat2str(myres)) ;

function a_num_Callback(hObject, eventdata, handles)
% hObject    handle to a_num (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 a_num as text
%        str2double(get(hObject,'String')) returns contents of a_num as a double
numa=str2double(get(hObject,'string'));
if isnan(numa)
      errordlg('请输入数字','输入错误','modal');
end
handles.numa=numa;
guidata(hObject, handles);

      

% --- Executes during object creation, after setting all properties.
function a_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to a_num (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.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function b_num_Callback(hObject, eventdata, handles)
% hObject    handle to b_num (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 b_num as text
%        str2double(get(hObject,'String')) returns contents of b_num as a double
numb=str2double(get(hObject,'string'));
if isnan(numb)
      errordlg('请输入数字','输入错误','modal');
end
handles.numb=numb;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function b_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to b_num (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.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function c_num_Callback(hObject, eventdata, handles)
% hObject    handle to c_num (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 c_num as text
%        str2double(get(hObject,'String')) returns contents of c_num as a double
numc=str2double(get(hObject,'string'));
if isnan(numc)
      errordlg('请输入数字','输入错误','modal');
end
handles.numc=numc;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function c_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to c_num (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.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

 用到的主要知识为:

1、get,set获取和设置属性

2、GUI上的控件,都在handles结构中,比如如果有个edit1的文本编辑框,则在M程序中表示为handles.edit1

3、使用guidata来更新GUI的共享数据,可用于控件之间交换数据,此外要加进handles的结构要在打开函数中增加

4、errordlg显示错误提示框

5、关于gco

 

>> help gco
 GCO Get handle to current object.
    OBJECT = GCO returns the current object in the current figure.
 
    OBJECT = GCO(FIG) returns the current object in the figure FIG.
 
    The current object is the last object clicked on, excluding
    uimenus.  If the click was not over a figure child, the
    figure itself will be the current object.
 
    The handle of the current object is stored in the figure
    property CurrentObject, and can be accessed directly using GET
    and SET.
 
    Use GCO in a callback to obtain the handle of the object that
    was clicked on.  MATLAB updates the current object before
    executing each callback, so the current object may change if
    one callback is interrupted by another.  To obtain the right
    handle during a callback, get the current object early, before
    any calls to DRAWNOW, WAITFOR, PAUSE, FIGURE, or GETFRAME which
    provide opportunities for other callbacks to interrupt.
 
    If no figures exist, GCO returns [].

 

  • 大小: 20.5 KB
  • 大小: 23.1 KB
分享到:
评论

相关推荐

    jiangbin2020-matlab-gui-examples-master.zip

    7. **编译与打包**:学习如何将MATLAB GUI程序编译为独立的可执行文件,方便在没有MATLAB环境的机器上运行。 8. **错误处理**:理解和运用错误处理机制,可以提升GUI的稳定性和用户体验。 通过"matlab-gui-...

    matlab-gui程序

    此文件设计matlab-gui的一些东西。

    第6-MATLAB-GUI程序设计初步.pptx

    第6-MATLAB-GUI程序设计初步.pptx

    Matlab-GUI编程实例(加法器).doc

    Matlab-GUI 编程实例(加法器)是一篇关于 Matlab-GUI 编程的教程,旨在指导读者如何使用 Matlab-GUI 实现一个简单的加法器程序。本篇教程分步骤讲解了如何创建一个 GUI 文件、添加控件、编写代码以实现两数相加的...

    Matlab-GUI在旅游路线优化上的应用.pdf

    Matlab可以用来设计旅游路线优化的程序,它能够结合GUI的设计思想和步骤,使用户能够通过界面直观地输入需要优化的景点,然后通过Matlab的计算功能输出优化后的路线。这样的程序不仅提高了用户体验,而且提高了效率...

    MATLAB-GUI_matlabGUI_

    在“MATLAB-GUI_matlabGUI_”的学习资源中,你将深入理解GUI设计的基本概念和实践技巧。 一、GUI设计基础 GUI设计主要涉及以下几个关键元素: 1. **控件**:如按钮、文本框、滑块、复选框等,用于接收用户的输入或...

    MATLAB-GUI开发案例源码.zip

    【工控老马出品,必属精品,亲测校正,质量保证】 资源名:MATLAB-GUI开发案例源码.zip 资源类型:程序源代码 源码说明: MATLAB-GUI开发案例源码 适合人群:新手及有一定经验的开发人员

    基于MATLAB-GUI的简易计算器设计.docx

    基于MATLAB-GUI的简易计算器设计是一个利用MATLAB的图形用户界面开发环境(GUIDE)构建的项目。MATLAB是一款强大的数学软件,主要用于算法开发、数据可视化、数据分析以及数值计算。它的GUI特性允许用户创建直观的、...

    精通MATLAB-GUI设计源代码-精通MATLAB-GUI的设计源代码.zip

    在GUI(图形用户界面)设计方面,MATLAB提供了丰富的工具和函数,使得非专业程序员也能构建出功能丰富的应用程序。本资料"精通MATLAB-GUI设计源代码"是针对这一主题的深入学习资源,旨在帮助用户掌握MATLAB GUI的...

    matlab-GUI.zip_MATLAB gui 画图_gui画图_matlab画图 程序_matlab画图gui

    MATLAB GUI程序通常包括“OpeningFcn”(初始化函数)、控件回调函数(如按钮按下事件)以及数据处理和绘图函数。 "mouse2.m"和"mouse.m"可能包含了与鼠标交互相关的函数。在MATLAB GUI中,可以编写这些函数来监听...

    数值分析程序matlab-GUI

    通过研究这个MATLAB-GUI程序,初学者可以学习到如何结合MATLAB的数值计算功能与GUI设计,创建自己的交互式应用,例如解决线性代数问题、进行拟合和优化、模拟动态系统等。同时,这也能帮助他们理解如何将复杂的算法...

    Matlab-GUI在偏振光实验中的应用.zip

    Matlab-GUI,全称是MATLAB图形用户界面(Graphical User Interface),是MATLAB编程环境中的一种工具,允许用户通过图形化方式与程序交互。在偏振光实验中,MATLAB-GUI可以作为数据采集、处理和分析的强大平台,帮助...

    第6章MATLAB-GUI程序设计.ppt

    ### 第6章:MATLAB-GUI程序设计 #### 一、MATLAB GUI程序设计概述 MATLAB提供了强大的GUI开发工具——GUIDE(Graphical User Interface Development Environment),用于帮助用户创建交互式的图形用户界面。通过...

    (精品)我的简易计算器MATLAB-gui程序.doc

    3. 回调函数的编写:在MATLAB GUI程序设计中,回调函数是指程序在响应用户交互事件时调用的函数。这些函数可以执行特定的操作,如计算、数据处理等。 二、MATLAB GUI程序实现 MATLAB GUI程序实现是指使用MATLAB...

    Matlab-GUI-基础编程.zip_GUI matlab_matlab GUI

    Matlab GUI(图形用户界面)是Matlab编程中一个强大的工具,它允许用户通过交互式界面与程序进行交互,而非仅仅依赖命令行操作。在"Matlab-GUI-基础编程.zip"这个压缩包中,包含了一份名为"Matlab-GUI-基础编程.pdf...

    MATLAB-GUI仿真资源

    # -MATLAB-GUI- 基于MATLAB的图像处理GUI软件 # 软件说明 本资源为基于MATLAB设计的数字图像处理软件源码,有自己设计的GUI、移植于MATLAB官网的标签页...simpletab.m程序,为标签页生成程序(MATLAB官网下载)。

    基于MATLAB-GUI的电机仿真管理系统-PPT课件.ppt

    该系统通过使用MATLAB-Simulink建立电机仿真程序,并使用MATLAB语言中的GUI设计用户界面。系统的主要功能包括电机状态方程的建立、仿真程序的设计、仿真结果的输出等。该系统的设计可以实现电机仿真的自动化、可视化...

    基于Matlab-GUI的汽车动力性分析.pdf

    GUI设计的主要目的包括方便函数的重复使用、为用户提供实用的函数或程序、以及创建交互式的分析方法示例。通过GUI,用户能够输入参数,操作软件,得到所需的动力性能评价指标的特性图。 综上所述,Matlab-GUI在汽车...

    STK-matlab GUI仿真程序

    "STK-matlab GUI仿真程序"是一个基于MATLAB的图形用户界面(GUI)应用程序,...如果你计划进入这个领域,建议从理解MATLAB基础开始,然后逐步学习STK的文档和相关教程,最后实践编写和调试GUI程序,以提升技能和经验。

Global site tag (gtag.js) - Google Analytics