How can I set the default figure size to full screen for use with a parfor loop?

35 views (last 30 days)
Caleb Thomas
Caleb Thomas on 27 Apr 2017
Commented: Caleb Thomas on 3 May 2017
I am modeling objects in flow with various orientations and animating the results using the movie command. I am storing figure frames for every loop iteration and then playing them back at the end. This works great for simple flows and few orientations, but takes a very long time for larger data sets (~20 minutes for approximately 80 orientations of an airfoil). I can cut down this time significantly using a parallel pool, but the issue that arises is that parfor will size the animation window to the the default figure size. I created a new full screen figure using
figure('units', 'normalized', 'outerposition', [0 0 1 1])
outside the loop and
set(gcf,'units','normalized','outerposition',[0 0 1 1])
inside the loop
however, when running the movie after calculations, every other run was still the default figure size. If I could set the default window size to full screen I believe it would solve the problem. I have attached the loop that gathers frames below.
note: I do realize that parfor is not great for this purpose, as it is non-sequential and may cause a mixup in the order of my frames. However, these effects have been negligible in my previous runs and the slight quality reduction will be worth the time savings for me.
close all
figure('units','normalized','outerposition',[0 0 1 1])
for i = 1:length(alpha)
levelAlpha = find(alpha == alpha(i)); %getting angle of attack
srcStrengths = ss(levelAlpha, :); %getting source Strengths
vortStrengths = sv(levelAlpha, :); %getting vortex Strengths
hold on
[hp, coords] = hessPlot(uinf, alpha(i), xCords, yCords, srcStrengths, vortStrengths, 'both', 1); %plotting use custom flow superposition function
title(['Hess-Smith Visualization for ', airfoil]);
patch(coords(:, 1), coords(:, 2), [.8 .8 .8]);
set(gcf,'units','normalized','outerposition',[0 0 1 1])
set(gcf, 'visible', 'off')
box on
legend(sprintf('\\alpha = %.1f^{\\circ}', alpha(i)))
frames(i) = getframe(gcf); %getting Frames
clf %clearing Figure
set(gcf, 'visible', 'on')
I appreciate any help that you can provide!

Answers (1)

Kevin Gleason
Kevin Gleason on 3 May 2017
You can set the default size of a figure by modifying the following default properties of the Graphics Root object:
>> set(groot, 'defaultFigureUnits','normalized')
>> set(groot, 'defaultFigurePosition',[0 0 1 1])
All figures created after this point will be full-screen.
It might also be worth it to create an array of figures to do this work, so that each worker will have its own figure to modify:
% Init Figures:
numWorkers = 2;
figNums = zeros(numWorkers,1);
for i=1:numWorkers
fig = figure;
fig.Position = [0 0 1 1];
figNums (i) = fig;
parfor i=1:10
figIdx = mod(i,numWorkers)+1; % index of figure to modify
fig = figure(figNums(figIdx)); % Figure to Modify
  1 Comment
Caleb Thomas
Caleb Thomas on 3 May 2017
Thank you! The default figure size does work! (the Guardians of the Galaxy fan in me is very amused by the graphics root handle). Sadly the axis itself does not take up the entire figure. While I can adjust the aspect ratio, I am unable to get the axis itself to increase in size. I'm afraid this might just be an inherent problem with running MATLAB parfor for graphics. That was also a very clever trick with assigning a figure to each worker, but sadly it did not work very efficiently for this application. Thank you again for your help!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!