Change the event of one button as another is pressed in matlab app designer

20 visualizaciones (últimos 30 días)
So, say you press a button in matlab, can it be used to change the function/event executed by a different button?
function Button1Pushed(app, event)
app.EditField.Value = "Hello"
end
% Button pushed function: InverseButton
function Button2Pushed(app, event)
app.Button1Pushed= "Goodbye" %doesn't work
end
This is what I have done so far.

Respuestas (1)

Mohammad Sami
Mohammad Sami el 15 de Mzo. de 2021
Instead of using a fixed string value in your function. create a property in your app and use that. you can then modify its value in another function, which will change the behaviour of the other function.
% under properties section
properties (Access = private)
myvalue = "Hello"; % default value.
end
% under functions section
function Button1Pushed(app, event)
app.EditField.Value = app.myvalue;
end
% Button pushed function: InverseButton
function Button2Pushed(app, event)
app.myvalue = "Goodbye" %change the default value
end

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!

Translated by