Adding and display in AppDesigner GUI
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mai Thành
el 7 de En. de 2022
Comentada: Mai Thành
el 7 de En. de 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 comentarios
Respuesta aceptada
Kevin Holly
el 7 de En. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!