Hy everybody, I would share soma variable from mat-file (workspace_invaso.mat) in AppDesigner, but I can't do it. I don't want to load the mat-file in every callback function. Best regard, Dario
% code
classdef Volume_invaso_1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UITable matlab.ui.control.Table
VOLUMEUTILEDINVASOLabel matlab.ui.control.Label
CapacitTextAreaLabel matlab.ui.control.Label
CapacityTextArea matlab.ui.control.TextArea
Button_Filo_Teso matlab.ui.control.Button
Button_Rippl matlab.ui.control.Button
Button_Peaks matlab.ui.control.Button
end
properties (Access = private)
load workspace_invaso.mat % Share variables
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
load workspace_invaso.mat;
app.UITable.Data=[Q_serie.annuale,Ve,Qu,Vu,Vc];
app.UITable.RowName={'Gennaio';'Febbraio';'Marzo';'Aprile';'Maggio';...
'Giugno';'Luglio';'Agosto';'Settembre';'Ottobre';'Novembre';'Dicembre'};
end

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 12 Mai 2018

0 votes

The startupFcn just execute once, at the start of the app, so you are loading the file just once, not at every callback.

4 commentaires

dario cecchetti
dario cecchetti le 12 Mai 2018
Yes I agree with you, but I would like to load mat file just once. I tried to do it in PROPERTY (acces==private), but Matlab get me an error.
I already said that startupFcn will only execute once. It appears that you are confused about how to share data after loading in startupFcn. You are getting the error because following is not a valid syntax
properties (Access = private)
load workspace_invaso.mat % Share variables
end
you can only declare the name of properties here.
Here is one way how you can share data between functions after loading. Create a private property data (or any other name) like this
properties (Access = private)
data
end
In the startupFcn, call the load() like this
app.data = load('workspace_invaso.mat');
this will return a struct with same fields as your mat file. For example, if your mat file has a variable named X, you can access it like app.data.X and this property is visible to all the function in the app so you can use app.data.(variable name) anywhere and access the required value.
dario cecchetti
dario cecchetti le 12 Mai 2018
Great! Thanks for all!!!
Ameer Hamza
Ameer Hamza le 13 Mai 2018
You are welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by