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

18 views (last 30 days)
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.

Answers (1)

Mohammad Sami
Mohammad Sami on 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

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!