Figure size when run from task scheduler

3 vues (au cours des 30 derniers jours)
Max
Max le 12 Mar 2021
Modifié(e) : Max le 15 Mar 2021
Dear community,
I would like to have a figure that is updated every midnight. So, I boot my computer automatically from the BIOS. Next, there are two scripts in the windows 10 task scheduler that are executed some time later with the setting: 'whether the user is logged on or not'. The first one scrapes some data and works absolutely fine. The second one starts the script, plots the figure, which works fine as well, except for the figure window size. The window size is as desired when I manually run the script with Matlab opened though!
The problem: The figure size should be about screen size (as give by 'position'), but is still Matlab default. In task manager the 'hidden' function is not selected. Matlab is not started with '-minimize -r', just '-r'. Alse, the program has highest privilages.
What I tried/investigated already: I have tried visible 'on', draw now, pause(5) to no avail. When the program is running still, and I log in on my computer, Matlab is running as a background process (which I think is core of the problem).
What I would like to have: primarily a solution to the figure position. Secondarily, the source of the problem and the mechanism of the solution for other Matlab users.
Code:
My_Plot = figure('visible','off','Renderer','Painters','Position',[1 41 1920 963]);
hold on
% the plot itself and the adjustments of the axis all come out the way it
% should be, except for the figure position.
draw now
pause(5); % or 0.02, but 5 doesn't do the trick
ax = gca;
ax.Position = [0.066 0.041 0.868 0.882];
hold off
draw now
pause(5);
Sincerely,
Max
edit(fixed typo's in the code after Jan's comment)

Réponses (1)

Jan
Jan le 12 Mar 2021
Modifié(e) : Jan le 12 Mar 2021
Is this really your code?
My_Plot = figure('visible','off','Renderer','Painters', ...
'Position','[1 41 1920 963]')
% ^ ??? ^ ???
No quotes here.
draw now ???
% Do you mean:
drawnow
You code fails here also:
ax.Position = [0.066 0.041 0.868 0.882];
% Undefined variable "ax"!
If nothing help and this is really true: "but is still Matlab default", then simply adjust Matlab's default:
set(groot, 'DefaultFigurePosition', [1 41 1920 963]);
Remember, that Matlab does not create figures larger than the screen. At least this was the case from Matlab 4.0 to 2018b. If I need this, I use: https://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi
I assume the lower position 41 is inside the taskbar and rejected for this reason. But then this would not happen: "The window size is as desired when I manually run the script with Matlab opened though!"
  2 commentaires
Max
Max le 12 Mar 2021
My apologies Jan, that's not my code indeed. Fixed the typo's in the original question.
Max
Max le 15 Mar 2021
Modifié(e) : Max le 15 Mar 2021
After some more testing, and then some:
1) set(groot, 'DefaultFigurePosition', [1 41 1920 963]); Same output as 'Position',[1 41 1920 963], which is smaller than desired. I assumed the figure size to be Matlab's default. Instead, I now believe that it is scaled to a maximum position that is not the same as the actual screen size.
The reason is this: [100 100 100 100] does scale the figure down, so DefaultFigurePosition has effect. [100 100 1200 900] creates a figure that is equally large as [100 100 1400 900], which is 1028x699 pixels. Therefore, a maximum size has been reached, before the monitor's maximum. 'WindowState','maximimum' results in a picture of 560x420 pixels.
2) windowAPI: "*** WindowAPI[mex]: getting HWND failed: Figure must be visible." 'visible','off' to 'visible','on' makes no difference. Not surprising since the application is running in the background.
--> So, in retrospect, My_Plot = figure('visible','off','Renderer','Painters','Position',[1 41 1920 963]); does change the position effectively, but only to a smaller window than the monitor resolution. And I'm back to the question: what to do to make the figure larger?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by