how can my app inherit from my classes

14 visualizzazioni (ultimi 30 giorni)
I have a class that can do some computations on some imported data. Now I would like to create an app with buttons for the methods in my class. Since I cant edit the first line in the "App Designer":
classdef App1 < matlab.apps.AppBase
is there another way of making my app inherit the methods and properties from my class?

Risposta accettata

Guillaume
Guillaume il 11 Gen 2017
The app (GUI) should not inherit methods from your class and it's a good thing matlab actually prevents it. This would be antithetical to the principle of OOP particularly encapsulation. The App class is designed to handle interaction with the GUI, nothing more. It certainly shouldn't expose the method of an unrelated class
The proper design is to have an instance of your class as public or private member( property) of the App class. You can instantiate that member at creation of the GUI (in the startup callback) and use its properties and methods anywhere from the app. So, the code would be something like:
classdef App1 < matlab.Apps.Appbase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
end
% Your own properties that you can edit:
properties (Access = private)
MyClass myobject % Description
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.myobject = MyClass(args);
end
end
  5 Commenti
Xingguo WU
Xingguo WU il 30 Giu 2020
Hi,
What's the practice to reuse custom UI components?
I wanted to inherit a panel class, and in this subclass I can already put other controls, finally to reuse this panel in main figure across different programs.
But seems I cannot inherit `matlab.ui.container.Panel`, error prompt saying something like "class not in the allowance list".
Noah Griffiths
Noah Griffiths il 30 Mar 2021
classdef App1 < matlab.Apps.Appbase
Anyone aware what this syntax means.
Is the class instantiated inside the app designer or outside?
Does anyone know if app is a parameter passed into the class or is it not necessary? Trying to think in terms of how matlab usually forces the app parameter in functions in appdesigner

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by