lag with "figure" function
1 次查看(过去 30 天)
显示 更早的评论
I have devised this function in order to make new figures appear where I want them to.
function figuree(varargin)
tic
if ~isempty(varargin)
if varargin{:}>0 && length(varargin{:})<2
figure(varargin{1})
else
error('illegal figuree arguments \n Arguments must be the same as figure')
end
else
toc
figure()
toc
end
set(gcf,'OuterPosition',[1,470,500,558])
This goes perfectly well.
But when I make for example this call:
close all
clear all
figure
figure
figure
figuree(2)
figuree
figuree(2)
figuree
this is my output:
Elapsed time is 0.000186 seconds.
Elapsed time is 0.260609 seconds.
Elapsed time is 0.000017 seconds.
Elapsed time is 3.168427 seconds.
My question is why do I have a sudden 3 second delay ??! (I will also accept advice about how to make new figure appear where I want them to)
0 个评论
采纳的回答
Matt Fig
2011-4-19
I have no idea why you are experiencing this huge delay. I put your exact code into an M-File and saved it. Then, pasting your code to the command line:
>> close all
clear all
figure
figure
figure
figuree(2)
figuree
figuree(2)
figuree
Elapsed time is 0.000473 seconds.
Elapsed time is 0.133531 seconds.
Elapsed time is 0.000035 seconds.
Elapsed time is 0.130823 seconds.
And these results are consistent. I can paste as many times as I like and see nearly the same numbers. I seriously doubt the event queue takes that long to flush because you start out with no graphics objects (the close all makes sure of that), and all figures are blank! Something else is going on....
As an alternative to using VARAGIN within the function the way you are, you could use NARGIN.
function figuree(NUM)
% Custom figure creation.
N = nargin;
if N==1
figure(NUM)
elseif N==0
figure()
end
set(gcf,'OuterPosition',[1,470,500,558])
Also, if you want your figures to always be there, put the default value assignment in your startup file. If you don't already have a startup file, just create one and make sure it is on your path. Every time you run MATLAB after that, startup.m will execute and set your figure default position.
更多回答(1 个)
Walter Roberson
2011-4-6
Have you considered
set(0,'DefaultFigureOuterPosition', [1,470,500,558])
figure() can take a variable length of time because MATLAB processes the event queue each time figure() is called.
3 个评论
Walter Roberson
2011-4-11
Your apparent 3 second delay might be because you have no toc() for the case where you pass arguments.
By the way, your code for working with varargin is not correct. Test it out by passing multiple arguments...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!