title: Getting current position of one of the multiple objects in a figure?
body: <p>I wrote a script that returns several text boxes in a figure. The text boxes are moveable (I can drag and drop them), and their positions are predetermined by the data in an input matrix (the data from the input matrix is applied to the respective positions of the boxes by nested for loop). I want to create a matrix which is initially a copy of the input matrix, but is UPDATED as I change the positions of the boxes by dragging them around. How would I update their positions? Here's the entire script</p>
  
  <pre><code>function drag_drop=drag_drop(tsinput,infoinput)
  [x,~]=size(tsinput);
  dragging = [];
  orPos = [];
  fig = figure('Name','Docker Tool','WindowButtonUpFcn',@dropObject,...
  'units','centimeters','WindowButtonMotionFcn',@moveObject,...
  'OuterPosition',[0 0 25 30]);
  % Setting variables to zero for the loop
  plat_qty=0;
  time_qty=0;
  k=0;
  a=0; 
  % Start loop
  z=1:2
      for idx=1:x
          if tsinput(idx,4)==1
              color='red';
          else
              color='blue';
          end
          a=tsinput(idx,z);
         b=a/100;
          c=floor(b); % hours
          d=c*100;
          e=a-d; % minutes
          time=c*60+e; % time quantity to be used in 'position'
          time_qty=time/15;
          plat_qty=tsinput(idx,3)*2;
          box=annotation('textbox','units','centimeters','position',...
          [time_qty plat_qty 1.5 1.5],'String',infoinput(idx,z),...
          'ButtonDownFcn',@dragObject,'BackgroundColor',color); 
          % need to new=get(box,'Position'), fill out matrix OUT of loop
      end
      fillmenu=uicontextmenu;
      hcb1 = 'set(gco, ''BackgroundColor'', ''red'')';
      hcb2 = 'set(gco, ''BackgroundColor'', ''blue'')';
      item1 = uimenu(fillmenu, 'Label', 'Train Full', 'Callback', hcb1);
      item2 = uimenu(fillmenu, 'Label', 'Train Empty', 'Callback', hcb2);
      hbox=findall(fig,'Type','hggroup');
      for jdx=1:x
          set(hbox(jdx),'uicontextmenu',fillmenu);
      end
  end
  new_arr=tsinput;
  
  function dragObject(hObject,eventdata)
  dragging = hObject;
  orPos = get(gcf,'CurrentPoint');
  end
  
  function dropObject(hObject,eventdata,box)
  if ~isempty(dragging)
      newPos = get(gcf,'CurrentPoint');
      posDiff = newPos - orPos;
      set(dragging,'Position',get(dragging,'Position') + ...
      [posDiff(1:2) 0 0]);
      dragging = [];
  end
  end
  
  function moveObject(hObject,eventdata)
  if ~isempty(dragging)
  newPos = get(gcf,'CurrentPoint');
  posDiff = newPos - orPos;
  orPos = newPos;
  set(dragging,'Position',get(dragging,'Position') + [posDiff(1:2) 0 0]);
  end
  end
  end
  
  % Testing purpose input matrices:
  % tsinput=[0345 0405 1 1 ; 0230 0300 2 0; 0540 0635 3 1; 0745 0800 4 1]
  % infoinput={'AJ35 NOT' 'KL21 MAN' 'XPRES'; 'ZW31 MAN' 'KM37 NEW' 'VISTA';
  % 'BC38 BIR' 'QU54 LON' 'XPRES'; 'XZ89 LEC' 'DE34 MSF' 'DERP'}
  </code></pre>