I got an answer from the MATLAB support team:
After collaborating with my colleagues I figured that this is a known limitation with the "uiaxes" performance in terms of rendering the images. Currently, "uiaxes"/"uifigure" (javascript based) does not support high frame rates like the traditional MATLAB figure window (java based) and the frames passed to the "uiaxes" are queued for rendering, this is causing the memory increase they noticed. For the same reason, it will cause a lag which worsens with larger images and high acquisition frame rates if the acquisition is running for a long duration .
Until the performance bottleneck in the "uiaxes" is addressed, there is little we can do to help you, if you goal is to have the live preview running in the app.
Having said that, for the time being, I would suggest you to open the preview in traditional MATLAB figure window outside of the app and i believe you have already tried this.
Another thing to experiment is to turn the imaqmex's "slowpreview" flag which currently sets a max limit of 10 frames for previewing. However, with the "uiaxes" rendering performance even 10 FPS might be high. Following is the code to enable slow preview.
>> imaqreset
>> imaqmex('feature', '-slowpreview', 'true')
>> vid = videoinput(...)Please note that this is an undocumented feature and it could change and/or be removed in the future.
Additionally, lowering the resolution and/or ROI can help as this decreases the load on the "uifigure".
Best Answer