mex file: monitoring (continuously) variables defined in matlab functions
3 次查看(过去 30 天)
显示 更早的评论
I have a TCP_IP camera and a GUI with some calc. functions written in matlab. Using mex file from c++ (provided by camera’s vendor), I’m able to open/close camera library and connection. The cpp allows changing some camera parameters like exposure. I’ d like to know if it is possible to monitor real time some variables (defined and changed in matlab) using mex file and when one of these changes the mex file does some operations on camera (ex. changing the exposure). One solution is to call the mex file every time a parameter in matlab is changed: but this method is quite inefficient. I guessed to write a sort of “thread” with a while loop inside the mex where the parameters/variables from matlab are transferred and could be monitored…but this method seems impracticable: I don’t know how to transfer variables from matlab continuously without calling the mex file every time. Any suggestion? Many thanks
Enrico
1 个评论
James Tursa
2015-6-17
"... but this method is quite inefficient ..."
Inefficient in what way? Are you having some type of speed or throughput issue with your current code, or what?
回答(1 个)
Andrew Schenk
2015-6-18
The best way of updating MATLAB variable values to an external library is to call the MEX function. It is not possible for the MEX file to "watch" a MATLAB variable. every time the parameter changes in MATLAB. That being said, here are some suggestions to improve the performance of your application:
If you are updating many parameters, you could pass them as a vector into the MEX function instead of calling the MEX function individually for each parameter.
From the description it sounds as if you have a single MEX function that opens the TCP connection, submits parameter changes, and then closes the connection. The overhead of opening and closing the connection is likely much larger than the parameter update. In this case it would be best to create three separate MEX functions to:
- Open the connection and return a handle
- Take the handle and parameter and submit the parameter update using the vendor's API
- Close the connection
This would be similar to the fopen, fwrite, fclose functions used in MATLAB for file I/O.
Finally, instead of having a callback in the GUI for when parameters change and automatically calling the MEX function, you could add an "Apply" button in the GUI that would call the MEX function with the parameter values only when clicked.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!