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
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!