Help for Out of memory issues while saving MATLAB figures

6 views (last 30 days)
I run a MATLAB script that loads a .MAT file into the workspace and generates plots, saves them as MATLAB figures and .bmp files. The MATLAB script is run based on a daily schedule setup in the control panel "Task Schedule".
During the process of generating plots and saving them, following is the sequence of operations:
1. A new figure window is generated 1. The figure window is maximized. I use a utility for this that I found in the MATLAB user community "File Exchange" 2. Plot or subplots are generated 3. Figure saved as a MATLAB figure 4. Figure saved as a .bmp file
Here is the problem: When the MATLAB script is executed via the schedule, MATLAB stops after saving the first plot as a MATLAB figure. While executing the save command for .bmp file, there is an OUT of Memory error message. However, if I execute the MATLAB script manually, there are no issues in executing all the above steps for 35 plots. So, I fail to understand what is driving this error.
  2 Comments
Jan
Jan on 20 May 2011
Please show the code, at least the command for saving to a BMP. Post a copy of the error message also. Can you determing the failing line using "dbstop if error"?
Do you close the figures after saving?
R Madhusudana Rao
R Madhusudana Rao on 7 Jun 2011
Jan,
below are the error messages and code
Error Message:
MEX-files with .dll extensions will not execute in a future version of MATLAB.
Warning: Failed in BitBlt, last error code 00000006, return code 0
> In F:\MatlabR2010a\toolbox\matlab\graphics\hardcopy.p>hardcopy at 21
In graphics\private\render at 143
In print at 291
In saveas at 155
In Create_Plots_Madhu at 70
??? Error using ==> print at 339
Out of memory. Type HELP MEMORY for your options.
Error in ==> saveas at 155
print( h, name, ['-d' dev{i}] )
Error in ==> Create_Plots_Madhu at 70
saveas(gcf,[plots_location '\' 'Stack_Metrics.bmp']);
Code:
% Plot for stack metrics - Plot # 1
figure
maximize; % Maximizes figure windows by using the Microsoft Windows application programming interface (API)
subplot(2,1,1);
plot(TIME,PowerStack,'LineWidth',2);
xlabel('Time (min)','FontName','Times New Roman','FontSize',12,'FontWeight','bold');
ylabel('Stack Power (KWDC)','FontName','Times New Roman','FontSize',12,'FontWeight','bold');
legend('Stack Power','Location','Best');
title(plots_title,'Interpreter','none','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
axis auto;
grid on;
subplot(2,1,2);
plot(TIME,VT100,TIME,CM100,TIME,CurReq,'LineWidth',2);
xlabel('Time (min)','FontName','Times New Roman','FontSize',12,'FontWeight','bold');
ylabel('VT100 (V) / CM100 (A) / CurReq (A)','FontName','Times New Roman','FontSize',12,'FontWeight','bold');
legend('VT100 (V)','CM100 (A)','CurReq (A)','Location','Best');
axis auto;
grid on;
set(gca,'FontSize',12);
% Save plot and close figure
saveas(gcf,[plots_location '\' 'Stack_Metrics.fig']);
dummy = 1; % Dummy statement to ensure above save command is executed completely
saveas(gcf,[plots_location '\' 'Stack_Metrics.bmp']);
dummy = 1; % Dummy statement to ensure above save command is executed completely
close
As you can see, the figures are closed after saving.
Thanks
Madhu

Sign in to comment.

Answers (1)

Jason Ross
Jason Ross on 7 Jun 2011
Task Scheduler jobs are run at a lower priority than interactive use. You can up the priority by editing the XML of the task in question. It also looks like Microsoft introduced the concept of "memory priority" in Vista and later, which makes the scheduled tasks prefer virtual memory.
If you google around, there are a number of workarounds to make your process work the same way as an interactive one.
I don't know if this is what's stopping you, but it seems like the task scheduler environment and normal desktop environment are different in terms of what they allow programs to do, since you can run more plots with the desktop mode.
  3 Comments
Jason Ross
Jason Ross on 13 Jun 2011
A number of things come to mind:
1. The service context in Windows XP allows you to check a tick box that says "allow this service to interact with the desktop". Is that checked or unchecked for Task Scheduler? WARNING: This behavior changes in Vista and higher, so don't rely on this to fix your problem. Although the tick box still exists, it doesn't do anything.
2. It's possible that calls you make on the remote machine that rely on the screen being available are returning nonsensical responses when the desktop is locked. I've definitely seen this happen before where a query to get the screen geometry that might expect something like "1280x1024" will return "0x0" or some negative number, which then confuses anything that expects a screen present. Although there may not be a way to effectively work around this, you might be able to at least determine if the screen is locked and handle the error more elegantly.
3. The XML thing may have been an enhancement for Vista that did not exist in XP, as I know MS made extensive changes to the way in which services interact with the desktop to support UAC to increase security, as noted in #1.
R Madhusudana Rao
R Madhusudana Rao on 15 Jun 2011
I tried a couple of options.
Option 1 that you suggested above did not work.
All the attempts below were tried with my desktop locked-out
1. I commented all the saveas .bmp lines. It works fine.
2. Instead of .bmp, I tried .jpg, .emf, .png and .tif. They all worked fine. .emf format is similar to .bmp in quality and also smaller in file size.
So, I will go ahead with saveas .emf format. Thanks for all your help and feedback with this issue.
Thanks
Madhu

Sign in to comment.

Categories

Find more on Printing and Saving 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!