Continuously Polling Data in Matlab GUI

2 views (last 30 days)
Torsten Fenn
Torsten Fenn on 22 Oct 2015
Answered: Geoff Hayes on 23 Oct 2015
Hi I have a GUI in MATLAB, which should be able to show the current position of a sensor in a statictext item. The form should read the signal all the time. Unfortunately I do not understand how to implement something like that in MATLAB. In C# you can easily create an eventhandler poll the data, whenever data is sent. How can I realize this in MATLAB? I can not use a while loop because I have to be able to push buttons and do other stuff with the GUI, while it reads the sensor. The sensor itself has functions and items i can get via a handle like:
hSensor = ConnectSensor(hSensor) handles.hSensor=hSensor position=SensorGet(handles.hSensor,xPos)
I know there are events which can be used, however all examples I found work with while loops.

Answers (1)

Geoff Hayes
Geoff Hayes on 23 Oct 2015
Torsten - one way in which you can achieve what you (probably) want is to create a timer that periodically polls your sensor and displays its position in the text control. See http://www.mathworks.com/matlabcentral/answers/178682-collecting-a-variable-every-two-minutes for a simple example of instantiating the timer and creating the timer callback. It is in the callback that you would poll the sensor for its position and then update the text control.

Categories

Find more on App Building 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!