Auto Refresh in app designer.
Show older comments
I have a couple of controls in my GUI but it can also happen that I control my system manually (sometimes). So the below image shows the lamps 1 and 2 ON (set and read by GUI after setting) but the 3rd one has turned ON anytime. When I turn the 3rd one ON, I want the GUI to change the lamp color and also the switch direction. I know commands to change the color of the lamp and switch position, but I am not getting how can I introduce this sensing part in my GUI.
In other words, I need a refresh function that can refresh the GUI at an as fast a rate as it can and then change the lamp colors accordingly.
Please let me know your inputs. Thanks a lot, in advance!

8 Comments
Adam Danz
on 6 Jun 2021
> I know commands to change the color of the lamp and switch position, but I am not getting how can I introduce this sensing part in my GUI.
You don't need to externally monitor the states of the switches & lamps. If lap colors 1 & 2 should change when lamp 3 changes, and if lamp 3 is changed by the user, then the callback function to lamp 3 should also change lamps 1 and 2.
If an external function controls lamp 3, instead of changing it direclty it could call a local app function that controlls all of the lamp states.
Many of your 50 questions have reasonable answers that are not accepted and with no replies. Please take the time to provide feedback to the volunteers who are solving your problems by either accepting answers that worked or leaving comments so that people know what works and what doesn't work. See your list of questions.
Jay Vaidya
on 6 Jun 2021
Adam Danz
on 6 Jun 2021
Can you edit the external function?
If so, instead of setting the lamp state directly within the external function, the external function can call a public function within your app. The public function would then controll all 3 lamp states. This is the most efficient and cleanest approach.
If the external function cannot be edited (which, I doubt is the case), you can set up a listener that triggers when there is a state change in lamp #3. See addlistener. This can be tricky to set up for the first time.
Jay Vaidya
on 7 Jun 2021
Adam Danz
on 7 Jun 2021
What's ROI? I thought you were listening to the switch or the lamp?
BTW, I realized that the Value propery of both objects is not set to be obsevervable so I'm not quite sure how to set a listener up for those objects.
Jay Vaidya
on 7 Jun 2021
J. Alex Lee
on 8 Jun 2021
Edited: J. Alex Lee
on 8 Jun 2021
in response to built-in classes where the value is not observable, if you are using a matlab release that has the new custom ui component (https://www.mathworks.com/help/matlab/developing-custom-ui-component-classes.html), you can wrap your switches into a custom app where you can "fake" access into the switch value.
in fact, it probably makes sense to create a custom component anyway that bundles a switch with a lamp. a lamp doesn't appear to have a "Value" anyway.
by the way, i still do not understand the situation with the "external script that is not editable"...how exactly is it interacting with your hardware and/or gui?
Adam Danz
on 8 Jun 2021
For the lamp you'd listen to the color property (which is also not observable).
The only scenario I can imagine where this makes sense it's that OP is not the owner of the app nor the external script (I hope it's a function) and cannot make changes to either files and the switch can be changed by progresses not within OP's control.
Accepted Answer
More Answers (0)
Categories
Find more on Desktop 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!