图形用户界面帮助MATLAB

图形用户界面帮助MATLAB,matlab,Matlab,因此,在完成一些基本的图像处理程序后,包括反转/镜像/过滤等,我想创建一个GUI,其中包括可以在打开的图像上执行这些程序的按钮。在玩弄了《向导》之后,我有点迷路了 所有这些回调/createfcn/buttondownfcn都让我有点困惑,我似乎无法正确理解语法 我尝试了各种方法使一个按钮对应于一个按钮的按下,包括 function X %just adding the name of a function after the green comment lines describing th

因此,在完成一些基本的图像处理程序后,包括反转/镜像/过滤等,我想创建一个GUI,其中包括可以在打开的图像上执行这些程序的按钮。在玩弄了《向导》之后,我有点迷路了

所有这些回调/createfcn/buttondownfcn都让我有点困惑,我似乎无法正确理解语法

我尝试了各种方法使一个按钮对应于一个按钮的按下,包括

 function X %just adding the name of a function after the green comment lines describing the three variables
但这并没有产生任何结果。我的问题是,我如何编程一个按钮,使其与我之前创建的函数相对应。我只是缺少某个功能,还是我不理解某个更广泛的概念


很抱歉,如果问题有点模糊,我对GUI的了解很少。

好的,我通常不喜欢指南GUI,但这里有一个非常简单的示例:

function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 18-Jun-2013 08:52:25

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_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
end

% --- Executes just before untitled is made visible.
function untitled_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 untitled (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line.
function varargout = untitled_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;
end

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
  % get a handle to the text field
  textDisp = get(handles.text1,'String');
  if( strcmp(textDisp{1},'Static Text' ) )
    set(handles.text1,'String',{'Checkout my new text'});
  elseif( strcmp(textDisp{1},'Checkout my new text') )
    set(handles.text1,'String',{'Clicked it 1 time'})
  else
    dd = sscanf(textDisp{1},'Clicked it %d time');
    dd = dd + 1;
    set(handles.text1,'String',{['Clicked it ' num2str(dd) ' time']})
  end
end
它将运行一个非常简单的图形,如下所示:


每次按下按钮时,它都会调用
pushbutton1\u回调
,其中包含
hObject
、导致回调的对象句柄、按钮、
eventdata
,在本例中它将为空,
handles
结构在本例中处理GUI中的所有内容。只需在回调函数或其他任何函数中进行图像处理,它就可以让您了解您要去的地方。嗯

在指南中创建uiobject时,将在相应的m文件中自动生成回调函数。将函数调用放在该回调中,当按下按钮时将执行该回调

如果有其他输入,例如文本框或选择框,则可以从回调中访问它们以读取变量输入

例如,如果您有一个带有标签
textbox1
的文本框,以及一个要使用texbox内容的函数,
myfun
,请在按钮的回调函数下放置以下内容:

str = get(handles.textbox1,'String');
myfun(str);

谢谢你的帮助。我如何编程我的GUI在任何输入的图像上执行功能,而不仅仅是在文本框中指定的一个特定图像?您可能需要查看
uigetfile
。您可以使用一个按钮调用
uigetfile
,然后使用
set(handles.textbox1,'String',fullfile(filepath,filename))将所选文件名和路径写入文本框
然后确保调用
guidata(hObject,handles)在回调结束时保存字符串。我遇到一个问题,即按钮打开文档浏览器,但在打开图像后没有关闭,我是否只是“关闭(uigetfile)”'或者是他们的其他方法?如何调用uigetfile?您的意思是选择文件并单击“确定”后,文件选择对话框不会关闭吗?修复了该问题,但出现了另一个问题。由于某些原因,My函数无法对打开的文件工作。错误“输入参数太多”“。如何设置程序来处理打开的文件?让fread()括号保持打开状态不起作用。