Example using a MATLAB Class to control a GUI

版本 1.2.0.0 (10.5 KB) 作者: Alex
This example shows how to use a Matlab class to control a gui.
3.1K 次下载
更新时间 2011/12/5

查看许可证

I've found, as my projects get bigger, it is easier to use a MATLAB class to control and manage a GUI instead of manipulating the standard Matlab gui mfiles.

I believe this style of GUI programming makes passing data around from different areas of gui much easier.

The functionality of this example is analogous to the built in Matlab example in GUIDE. This example is purely to show another way to solve the same problem. This example can be extended to many other applications.

Running command: gui_class_example()

%gui_class_example
%
% This exmaple shows how to use a MATLAB CLASSDEF to create, maintain, and
% destroy a gui.

% I chose to use one of the standard MATLAB guide default gui examples,
% this allows you to see the differences between the two methods.

% I prefer using classes to control gui's because as the project gets
% larger, I find it much easier to maintain, understand, and debug using a
% class bases sytem than using the traditional gui based system.

% Also, this method is great for passing data between elements of the gui.
% Since the class managed the gui, all gui elems are within memory scope of
% the class.

% Almost everything is the same between managing a gui through the gui
% mfile and a class. There are 2 main differences that I've noticed.

% 1. With the class based system, you do not need to store and set the
% guidata to obtain and pass data along

% 2. Cleanup is harder using the Class based system. There are 2 objects in
% memory, the gui itself and the class. These must be linked in some way
% that if one is closed or destroyed, the other is taken care of. I show
% one solution to this siutation here by adding a closerequestfcn to the
% figure. This function then calls the class's delete function to clean up
% the memory (preventing memory leaks).

引用格式

Alex (2024). Example using a MATLAB Class to control a GUI (https://www.mathworks.com/matlabcentral/fileexchange/33816-example-using-a-matlab-class-to-control-a-gui), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2011b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Migrate GUIDE Apps 的更多信息
致谢

启发作品: Model-View-Presenter example GUI

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.2.0.0

The mfile for the fig was added.

1.0.0.0