standalone executable to run on virtual Windows server and save figure plot to .png file
Show older comments
I have written a m file which processes and displays an image to a figure window and then saves the figure to a png file.
I compiled it to a standalone excutable and it runs fine on my PC where I devloped it.
When I run this on run on virtual Windows server (the deployment target) it does not run, it just hangs
The function doing this part is (and it all works fine on server if I don't call this):
function displayROIs(I,iminfo)
% cfig=figure('visible','off')
imshow(I);
hold on;
axis on;
% drawnow;
[filepath,filename,ext] = fileparts(iminfo.Filename);
expFilename=strcat(filepath,'\',filename,' CNR.','png');
%exportgraphics(cfig,expFilename)
saveas(cfig,expFilename)
end
thanks for any help offered.
4 Comments
Walter Roberson
on 30 Sep 2025
I suggest experrimenting with
function displayROIs(I,iminfo)
cfig = figure('visible','off')
ax = gca(cfig);
imshow(ax, I);
hold(ax, 'on');
axis(ax, 'on');
% drawnow;
[filepath,filename,ext] = fileparts(iminfo.Filename);
expFilename=strcat(filepath,'\',filename,' CNR.','png');
%exportgraphics(cfig,expFilename)
saveas(cfig,expFilename)
end
Nick Gibson
on 1 Oct 2025
Spoorthy Kannur
on 11 Nov 2025
Hi Nick,
It appears that the executable hangs because graphics commands like “figure”, “imshow”, and “gca” require a graphical display, which might not be available on your virtual Windows Server. In headless environments, such calls can hang or fail silently.
You can try the following workarounds:
- Avoid creating a visible figure. Instead, render directly to an offscreen image using “imwrite” or “exportgraphics” on a “uifigure” created with 'Visible','off'.
- Alternatively, use the “figure('Visible','off')” approach but ensure the MCR has access to an OpenGL software renderer (you can set “opengl('save','software'”) before compiling). (https://www.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it.html)
- If the server runs without GUI support, try using “getframe” or “imwrite” to save the processed image instead of relying on “imshow + saveas”. Something like this:
- If this still hangs, it likely confirms the environment lacks GUI capabilities. In that case, consider running MATLAB or the executable on a machine with graphical support or through a remote desktop session that provides a display context (https://www.mathworks.com/matlabcentral/answers/44860-save-figure-on-a-server-machine-with-no-display.html)
If this does resolve the issue, kindly reach out to MathWorks Technical Support for more help (https://www.mathworks.com/support/contact_us.html)
Nick Gibson
on 11 Nov 2025
Answers (0)
Categories
Find more on MATLAB Compiler 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!