Random ordering of figure numbers

8 次查看(过去 30 天)
Christopher Ison
Christopher Ison 2015-9-28
评论: Jon 2015-9-30
When I installed R2015a, figure numbers were then generated in random order. I have a script that produces many graphs at once, then tiles them. I was astonished to find they would no longer display in the order executed. The figure numbers were correct but they did not arrange in numerical order when tiled. This never happened before. Any clues as to what's going on? Could it be the tiling function? I checked get(0, 'Children') and it lists the figures in reverse display order (first is last in the list). FWIW, when the tiling function is not used, figures stack on one another in numerical order.
  3 个评论
Walter Roberson
Walter Roberson 2015-9-28
Are you referring to the tiling feature described over here ?
Mike Garrity
Mike Garrity 2015-9-29
This is just a guess, but I suspect that the code you're using to do the tiling is using GCF. If you create a bunch of figures in a row without calling drawnow, then which one becomes GCF is up to the operating system. This was always a bit unpredictable, but with the new multithreaded graphics system which was introduced in R2014b it became rather more unpredictable.
For this sort of thing, it is probably better not to depend on the value of GCF. Instead, use the return value of the figure function. Or, as you've noticed, you can look at the children of the root object. Either of those should be more predictable.
Alternatively, you could try adding some calls to drawnow to your code to try and keep the threads more in synch, but I don't think that would be a very robust solution.
But, as I said, this is just a guess and I may be all wet.

请先登录,再进行评论。

回答(1 个)

Christopher Ison
Christopher Ison 2015-9-29
In response to the request to post the code, here it is. I think we DL'd via The Mathworks long ago. I'm interested to learn how to bring it up to date. I'm surprised this isn't included in MATLAB's core functions.
function tilefigs(tile,border)
% <cpp> tile figure windows usage: tilefigs ([nrows ncols],border_in pixels)
% Restriction: maximum of 100 figure windows
% Without arguments, tilefigs will determine the closest N x N grid
%Charles Plum Nichols Research Corp.
%<cplum@nichols.com> 70 Westview Street
%Tel: (781) 862-9400 Kilnbrook IV
%Fax: (781) 862-9485 Lexington, MA 02173
maxpos = get (0,'screensize'); % determine terminal size in pixels
maxpos(4) = maxpos(4) - 25;
hands = get (0,'Children'); % locate fall open figure handles
hands = sort(hands); % sort figure handles
numfigs = size(hands,1); % number of open figures
maxfigs = 100;
if (numfigs>maxfigs) % figure limit check
disp([' More than ' num2str(maxfigs) ' figures ... get serious pal'])
return
end
if nargin == 0
maxfactor = sqrt(maxfigs); % max number of figures per row or column
sq = [2:maxfactor].^2; % vector of integer squares
sq = sq(find(sq>=numfigs)); % determine square grid size
gridsize = sq(1); % best grid size
nrows = sqrt(gridsize); % figure size screen scale factor
ncols = nrows; % figure size screen scale factor
elseif nargin > 0
nrows = tile(1);
ncols = tile(2);
if numfigs > nrows*ncols
disp ([' requested tile size too small for ' ...
num2str(numfigs) ' open figures '])
return
end
end
if nargin < 2
border = 0;
else
maxpos(3) = maxpos(3) - 2*border;
maxpos(4) = maxpos(4) - 2*border;
end
xlen = fix(maxpos(3)/ncols) - 30+20; % new tiled figure width
ylen = fix(maxpos(4)/nrows) - 45-30; % new tiled figure height
% tile figures by postiion
% Location (1,1) is at bottom left corner
pnum=0;
for iy = 1:nrows
ypos = maxpos(4) - fix((iy)*maxpos(4)/nrows) + border +25; % figure location (row)
for ix = 1:ncols
xpos = fix((ix-1)*maxpos(3)/ncols + 1) + border+7; % figure location (column)
pnum = pnum+1;
if (pnum>numfigs)
break
else
figure(hands(pnum))
set(hands(pnum),'Position',[ xpos ypos xlen ylen ]); % move figure
end
end
end
return
  1 个评论
Jon
Jon 2015-9-30
How are you creating the figures? In a loop like this?
for i = 1:N
figure(i) = plot(whatever);
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by