Effacer les filtres
Effacer les filtres

Adding and display in AppDesigner GUI

1 vue (au cours des 30 derniers jours)
Mai Thành
Mai Thành le 7 Jan 2022
Commenté : Mai Thành le 7 Jan 2022
I have a small code below to adding and display the value when users press the button. But there is something wrong here, can anyone help me, please
function Button_57Pushed(app, event)
x2=0;
x2=x2 + 1;
app.Label_2.Text='x2 value, x2';
end
Also, the error message said that x2 might be unused.

Réponse acceptée

Kevin Holly
Kevin Holly le 7 Jan 2022
How do you want the text to be displayed?
If you want it to display 'x2 value, 1', you can do the following:
function Button_57Pushed(app, event)
x2=0;
x2=x2 + 1;
app.Label_2.Text=['x2 value, ' num2str(x2)];
end
Not this will always make x2 = 1, since x2 is defined as 0 at the beginning of function. I would remove x2=0 from the function. If you need to preallocate the variable and this is a counter, you need to define it outside the function. You do this in properties (Access = Public). Then you can access the variable with app.x2.
properties (Access = public)
x2 = 0
end
function Button_57Pushed(app, event)
app.x2=x2 + 1;
app.Label_2.Text=['x2 value, ' num2str(app.x2)];
end
  1 commentaire
Mai Thành
Mai Thành le 7 Jan 2022
Thank you very much !!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by