Adding and display in AppDesigner GUI
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mai Thành
am 7 Jan. 2022
Kommentiert: Mai Thành
am 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.
0 Kommentare
Akzeptierte Antwort
Kevin Holly
am 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!