简体   繁体   English

使用SizeChangedFcn的Matlab不使用指南调用函数

[英]matlab using SizeChangedFcn doesn't call function using guide

I want to implement some code so when the user resizes the window I can call a function. 我想实现一些代码,以便当用户调整窗口大小时可以调用一个函数。 I am using matlab 2018 and they recommend using the SizeChangedFcn instead of ResizeFcn. 我正在使用matlab 2018,他们建议使用SizeChangedFcn而不是ResizeFcn。 I haven't messed with callbacks too much, but I am having trouble getting my gui to call the SizeChangedFcn each time the window is resized. 我并没有过多地处理回调,但是我很难让我的GUI每次调整窗口大小时都调用SizeChangedFcn。 Currenlty, the function isn't called at all. Currenlty,根本没有调用该函数。

function varargout = firstgui(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ... 
                   'gui_OpeningFcn', @firstgui_OpeningFcn, ...
                   'gui_OutputFcn',  @firstgui_OutputFcn, ...
                   'SizeChangedFcn', @resizeui, ... % <-- added this line
                   '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


function resizeui(hObject,event)
        disp("Hi");

Edit: 编辑:

I should mention that I am using a program that relies heavily on guide so I am stuck with that implementation. 我应该提到的是,我使用的程序严重依赖于指南,因此我坚持使用该实现。

Here is what is in "gui_mainfcn" 这是“ gui_mainfcn”中的内容

function varargout = gui_mainfcn(gui_State, varargin)
% GUI_MAINFCN Support function for creation and callback dispatch of GUIDE GUIs. 
%   GUI_MAINFCN is called from inside MATLAB code files generated by GUIDE to handle
%   GUI creation, layout, and callback dispatch.
%
%   See also: GUIDE.

%   GUI_MAINFCN provides these command line APIs for dealing with GUIs
%
%      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_OpeningFunction 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)".

%   Copyright 1984-2015 The MathWorks, Inc.

gui_StateFields =  {'gui_Name'
    'gui_Singleton'
    'gui_OpeningFcn'
    'gui_OutputFcn'
    'SizeChangedFcn' %added this line as well does not work yet
    'gui_LayoutFcn'
    'gui_Callback'};

I found the solution here: 我在这里找到解决方案:

https://www.mathworks.com/help/matlab/creating_guis/gui-options.html https://www.mathworks.com/help/matlab/creating_guis/gui-options.html

Access the dialog box from the GUIDE Layout Editor by selecting Tools > GUI Options. 通过选择“工具”>“ GUI选项”,从GUIDE布局编辑器访问对话框。

Other (Use SizeChangedFcn) — Program the UI to behave in a certain way when users resize the figure window. 其他(使用SizeChangedFcn)-对UI进行编程,以在用户调整图形窗口的大小时以某种方式运行。

When selecting "SizeChangedFcn" in the gui options it created a function for me. 在gui选项中选择“ SizeChangedFcn”时,它为我创建了一个函数。

function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp("Hi");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM