Is it possible to get data from Matlab during runtime using C compiler?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm using Matlab compiler to call from C code Matlab functions. But they have to run relevantly long time (`parfor` etc. parallelization in Matlab does not speed up).
So it would be beneficial if I can "hook" C callback to get data (like some matrix) from Matlab while it's running.
Is it possible?
0 Kommentare
Antworten (1)
Aniket
am 19 Sep. 2024
I understand that you want to retrieve data from MATLAB functions called from C code, especially when these functions run for a long time. I believe that MATLAB's runtime environment may not be inherently designed to provide real-time data exchange while executing functions, particularly when using compiled MATLAB code.
However, here are some approaches you can consider:
1. MATLAB Engine API:
- The MATLAB Engine API allows you to start and communicate with a MATLAB session from your C program. This approach provides flexibility by enabling you to execute MATLAB commands and retrieve results programmatically. However, it requires running MATLAB as a separate process.
For further details, refer to these links:
2. Custom MEX Function:
- If you have control over the MATLAB code, you can create a custom MEX function to act as an interface between MATLAB and your C code. This allows you to pass data back to C at specific points during MATLAB execution. You will need to modify the MATLAB code to explicitly call this MEX function.
You can get more information regarding MEX functions here:
3. Polling with Intermediate Storage:
- Modify your MATLAB code to periodically save intermediate results to a file or a database. Your C code can then poll this storage to retrieve the data. This method is simple but might introduce some overhead due to file I/O operations.
Also, if parfor is not speeding up your code, consider using other parallel computing strategies, such as spmd, parfeval, or batch functions. These might offer better performance depending on your specific use case. While this doesn't directly solve the data retrieval problem, it might help reduce execution time, potentially making real-time data retrieval less critical.
I hope this gets you on the right track!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!