title: how to return a value from a user defined function in matlab whose callback is specified in uicontrol
body: <p>I have the following code to run for resizing an image on a figure window. for this I wrote this code on a script file: </p>
  
  <pre><code>%%%f=figure('name','resize','color','w','windowstyle','modal','numbertitle','off','position',[820 110 500 612],'resize','on')
  % Removed "'windowstyle','modal'" to allow debug
  f=figure('name','resize','color','w','numbertitle','off', ...
           'position',[820 110 500 612],'resize','on')
  
  hx=axes('Units','inches');
  
  hax = imread('c.jpg');
  imshow('c.jpg')
  sli=uicontrol('Style','slider',...
      'Min',1,'Max',4,'Value',2,...
      'Position',[50 525 400 20],...
      'Callback', {@resiz,hax})
  
  y=getappdata(0,'x');
  
  uicontrol('Style','text',...
      'Position',[50 555 400 20],...
      'String','Resize');
  
  uicontrol('Style','pushbutton',...
      'Position',[30 565 100 40],...
      'String','Save','Callback',{@save,y});
  uicontrol('Style','pushbutton',...
      'Position',[200 565 100 40],...
      'String','Cancel','Callback',@cancel);
  </code></pre>
  
  <p>along with the above code I have a function definition code for resiz() which has save() and cancel() nested in it as follows:</p>
  
  <pre><code>function x=resiz(hObj,event,ax) %#ok&lt;INUSL&gt;
  
  val =get(hObj,'Value');
  if val==1
      v=256;
  else
      v=(val-1)*2*256;
  end
   s=[v v];
  ax=imresize(ax,s);
    imshow(ax)
    setappdata(0,'x',ax);
  function save(hObj,event,im)
  
    imwrite(im,'gt.jpg','jpg');
  return
  
  function cancel(hObj,event)
      close(hObj);
  return
  %%%return;
  </code></pre>
  
  <p>I have already gone through setappdata and getappdata but couldn't find any solution. Can anyone please help me get through this.</p>