standalone executable to run on virtual Windows server and save figure plot to .png file

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

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
thank you for your suggestion Walter.
However, no different.
(I had to use imshow(I,'Parent',ax);)
from logging I think it's falling over at the line: ax = gca(cfig);
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:
If this does resolve the issue, kindly reach out to MathWorks Technical Support for more help (https://www.mathworks.com/support/contact_us.html)
Hi, thanks for you response, I will check out these aproaches.

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Release

R2025a

Asked:

on 30 Sep 2025

Commented:

on 11 Nov 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!