Scheduled script doesn't produce expected figure

Hello! I'm trying to schedule a Matlab 2020b script by using Windows 10 Task Scheduler, using the -batch options as suggested by Matlab user guide.
The script produces a two sub-plots .fig and, using the code
exportgraphics(fig,FILEJPG,'Resolution',300);
the corresponding .jpg.
Unlukily, despite I programmatically set all the "positions" variables in the correct way, the .fig and .jpg files obtained by running the same identical script from the Matlab IDE or through Windows scheduler differs. The script contains the following code:
fig=figure('Position', [1 1 1920 1007]);
ah=subplot(2,1,1, 'Position', [0.0421,0.5825,0.9362,0.3622]); %upper sub-plot position
%... code to plot data
al=subplot(2,1,2, 'Position', [0.0421,0.0957,0.9362,0.3622]); %lower sub-plot position
%... code to plot data
%The following are printed out just to compare the output while interactively running
% the code vs output recorded on logfile when script is run via TaskScheduler
fig.OuterPosition
fig.Position
fig.InnerPosition
fig.WindowState
fig.CurrentAxes
%Code used to save .fig and .jpg files
saveas(fig,FILEFIG);
exportgraphics(fig,FILEJPG,'Resolution',300);
Output found in Command Window is identical to that recorded in logfile when the script runs through Windows scheduler. However, the two output .jpg files follow: above I show the file obtained by an interactive run, below the same file obtained by the scheduled run.
Files differ mostly for label dimension and position, and it seems like less control on outputted files is available when script is run in non-interactive mode.
I tried to avoid a complete non-interactive mode, but I wasn't able to display from Task Scheduler the Matlab IDE nor the figure window.

Answers (1)

Products

Release

R2020b

Asked:

on 18 Jan 2021

Commented:

Tim
on 22 Jan 2024

Community Treasure Hunt

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

Start Hunting!