title: using timer in MATLAB to extract the system time
body: <p><img src="https://i.stack.imgur.com/sqHsO.png" alt="enter image description here">!I am using MATLAB to design an Analog Clock. Currently, my code simply displays the (or plots rather) the clock design with the hands (hours, mins, secs) and does not tick. Here is my code:</p>
  
  <pre><code>function raviClock(h,m,s)
  drawClockFace;
  
  
  %TIMER begins-------
  t = timer;
  t.ExecutionMode = 'FixedSpacing';  %Use one of the repeating modes
  t.Period = 1;                      %Fire on 1 second intervals
  t.TimerFcn = @timer_setup;           %When fired, call this function
  start(t);
  set(gcf,'DeleteFcn',@(~,~)stop(t));
  end
  
  function timer_setup(varargin)
  
  format shortg;
  timenow = clock;
  h = timenow(4);
  m = timenow(5);
  s = timenow(6);
  
  % hour hand
  hours= h + m/60 + s/3600;
  hourAngle= 90 - hours*(360/12);
  
  % compute coordinates for pointing end of hour hand and draw it
  [xhour, yhour]= polar2xy(0.6, hourAngle);
  plot([0 xhour], [0 yhour], 'k-','linewidth',7.4)
  
  % minute hand
  mins= m + s/60;
  minsAngle= 90 - mins*(360/60);
  
  % compute coordinates for pointing end of minute hand and draw it
  [xmins, ymins]= polar2xy(0.75, minsAngle);
  plot([0 xmins], [0 ymins], 'r-','linewidth',4)
  
  
  %second's hand
  second = s;
  secAngle = 90- second*(360/60);
  
  [xsec, ysec]= polar2xy(0.85, secAngle);
  plot([0 xsec], [0 ysec], 'm:','linewidth',2)
  %end   % while ends
  end
  
  %--------------------------------------------------------
  
  function drawClockFace
  
  %close all          
  axis([-1.2 1.2 -1.2 1.2])  
  axis square equal
  hold on            
  
  
  theta= 0;
  for k= 0:59
      [xX,yY]= polar2xy(1.05,theta);
          plot(xX,yY,'k*')
  
          [x,y]= polar2xy(0.9,theta);
      if ( mod(k,5)==0 )  % hour mark
          plot(x,y,'&lt;')
      else                % minute mark
          plot(x,y,'r*')
      end
      theta= theta + 360/60;
      end
  end
  
  %-----------------------------------------------------------------
  function [x, y] = polar2xy(r,theta)
  
  rads= theta*pi/180;  
  x= r*cos(rads);
  y= r*sin(rads);
  end
  </code></pre>
  
  <p>This is simply taking a static data of values for the HOUR, MINUTE and SECOND arguments when i initially call my function. I tried using the following in a while loop but it didn't help much</p>
  
  <pre><code>format shortg
  c=clock
  clockData = fix(c)
  h = clockData(4)
  m = clockData(5)
  s = clockData(6)
  </code></pre>
  
  <p>and passing the h, m and s to the respective cuntions. I want to know how I can use the TIMER obkjects and callbacks for extracting the information of [hrs mins secs] so i can compute the respective point co-ordinates in real time as the clock ticks.</p>