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

조회 수: 34 (최근 30일)
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
end
set(gcf, 'visible', 'on')
I appreciate any help that you can provide!

답변 (1개)

Kevin Gleason
Kevin Gleason 2017년 5월 3일
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;
end
parfor i=1:10
figIdx = mod(i,numWorkers)+1; % index of figure to modify
fig = figure(figNums(figIdx)); % Figure to Modify
end
  댓글 수: 1
Caleb Thomas
Caleb Thomas 2017년 5월 3일
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!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by