Ploting issues when running Matlab with Task scheduler on a virtual machine on a server.

2 次查看(过去 30 天)
I have a script that emails out two reports. Windows 10 Task Scheduler runs the script at set times of day.
The Pseudo code is as follows;
  • Get data
  • Do calculations
  • Populate excel template 1 spreadsheet using - 'xlswrite'
  • Create PDF using - 'xls2pdf'
  • Plot Data using - 'plot'
  • Insert plotted figure onto excel template 2 spreadsheet using - 'xlsputimage'
  • Create PDF using - 'xls2pdf'
  • Attach pdfs to email and send.
I have MATLAB set up on a virtual machine running Windows 10 on a server, which I acces via Remote Desktop.
On the Virtual Machine I have set up a task in Task Scheduler to run my script at the specified times. This all works fine.
When I am logged into the virtual machine (with Remote desktop) the script produces a perfect report when a) I run it in MATLAB, or b) if the task scheduler runs the script (while I'm logged in).
My issue is that when I am not logged into the virtual machine, both reports are not positioned correctly on the pdf. The first report where i have input arrays onto an excel template 1, the print area has become smaller, such that page 2 headings are printed on page 1. While, the second report the figure is enlarged and the edges are cut off.
I am not getting any errors from the script, just a rubbish report.
Any help will be much appreciated.

回答(1 个)

Riya
Riya 2024-1-22
Hello Charl,
When running scripts that involve graphical elements or Office automation on a virtual machine without an active user session (i.e., no one is logged in), you may encounter issues due to the lack of a desktop environment that some processes depend on.
Here are several steps you can take to troubleshoot and potentially resolve the issue:
  • For Excel operations, ensure that the Excel application is set to run in the background. You can achieve this by setting the `Visible` property of the Excel application to `false` in your MATLAB code.
excelApp = actxserver('Excel.Application');
excelApp.Visible = false;
% ... your code to interact with Excel ...
excelApp.Quit();
  • Be aware of Session 0 isolation in Windows services. Services in Windows (including scheduled tasks running without a user logged in) run in Session 0, which does not have access to the graphical subsystem in the same way a user's session does.
  • In Task Scheduler, make sure that the task is configured to "Run whether user is logged on or not" and that you have checked "Run with highest privileges."
  • Use MATLAB's batch function: This function is designed to run MATLAB code in the background on a MATLAB worker session. It's typically used with the Parallel Computing Toolbox but can also run tasks that do not require user interaction.
Refer the following article about how to run files in batch mode or as a batch process:

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by