How can I call an event Function in AppDesigner

Hello,
I want to call in the startupFcn an Event Function from my Switch. If I set progammily the Value from the Switch to 'Off', they changed only the Value. But I want to call the event Function from this Switch, if I start the App in AppDesigner. How can I do this?

2 Comments

Your question is not very clear.
Nonetheless, event functions are just normal functions, you can call them from any other function (as long as you pass it the arguments it requires).
However, it's very unusual to have to call a startupFcn once your app is started. As the name indicates, it's only supposed to be called at the start to initialise the app. If there is part of the startup that you want to repeat at a later time, then you would be better off extracting that repeating part into its own function, that you'd call from the startupFcn and whichever other function you'd want.
Ok, also this is the Callback Function:
function currentStatusValueChanged(app, event)
...
end
And i want to call this function in the Startup function or in other functions. But my Problem is, i have not the input argument "event".
Unbenannt.JPG

Sign in to comment.

 Accepted Answer

Ah, so you want to call a control from the statupFcn, that makes more sense.
If you're not using the event argument in the function, just pass [] when you call the function. If you are using the event argument, you can create a new event argument with:
event = matlab.ui.eventdata.ValueChangedData(value, previousvalue); %replace value and previousvalue by actual states 'On' and 'Off'
I've not found a way to set the Source and EventName property so if you do use these in the callback, you'll have to modify the callback, or as I said, extract the common code into its own function called by both callbacks.

1 Comment

I've come across this, too. Not being able to set EventName and Source is not that great. I've checked matlab.ui.eventdata.ValueChangedData, it just adds dynamic properties given as pv pairs. No chance to modify existing properties though.
Any workarounds? I'm using a struct right now but that's really not nice:
event = matlab.ui.eventdata.ValueChangedData(0, 1, ValueIndex=1, EventName="Manual Trigger");
event = struct("ValueIndex", 1, "EventName", "Manual Trigger", "Source", mySrcOb); % this is not nice, a class would be better

Sign in to comment.

More Answers (0)

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!