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

24 vues (au cours des 30 derniers jours)
Tb
Tb le 15 Mar 2021
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.

Réponses (1)

Mohammad Sami
Mohammad Sami le 15 Mar 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

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