Draw using an existing figure object/canvas in MATLAB -


i trying animate clock hand's movement using matlab. created 'draw_clock()' program/script in file named 'draw_clock.m' goes this.

function draw_clock()     set_figure();     draw_clock_hands(); end  function set_figure()     figure;     hold on;     axis off;     title('clock'); end 

then have script file named 'animate_clock.m' has this:

hours = 0:12; minutes = 0:59; = 1:numel(hours)     j = 1:numel(minutes)         draw_clock();         pause(0.05);         refresh;     end end 

when run 'animate_clock.m', new window/clock figure every frame opened instead of redrawing on same canvas/figure. understand why happening because 'set_figure()' being called every time 'draw_clock()' called. i'm new matlab, if there's way stop creating new figure code skeleton above. guess if can detect if there's figure object opened, can skip calling 'set_figure()' inside 'draw_clock()' next time being called?

thank in advance answers!

so after searching , reading doc bit, think there couple of different ways detect if matlab figure exists. 1 found useful (and relatively simple) to: - assign 'name' property figure window - find if object assigned name exists using 'findobj(...)' method - if figure exists, use 'hold on' reuse old figure - else, create new figure name 'figure('name', 'foo figure')'

for case, 'set_figure()' method become this:

function set_figure()     fig_name = 'my clock';     if isempty(findobj('name', fig_name))         figure('name', fig_name);     end      hold on;     axis off; end         

hope can come , improve become more robust. :)


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -