lag with "figure" function

2 次查看(过去 30 天)
j dr
j dr 2011-4-6
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)

采纳的回答

Matt Fig
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
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
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...
j dr
j dr 2011-4-19
indeed, any figure called after calling my script:
close all
clear all
figure
figure
figure
figuree(2)
figuree
figuree(2)
%%%%
tic
figure
toc
will take 3 seconds... Is it that I filled the "queue" with my previous callings ? Is this due to my supposed misuse of varargin?
Also the varargin works for me. The figure function is not supposed to be called with multiple arguments, only with either 0 or 1 arguments and I couldn't find any other way to make it work for both these cases.
Please keep me posted !

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by