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 (2025). 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 Center および MATLAB AnswersMigrate 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