title: how to pass value among functions in MATLAB GUI?
body: <p>I'm trying to convert an image file into a binary file, where I'm using 2 buttons in Matlab GUI.
  the first button it to browse the files then shows the file name on a static text, and the second button for saving it as a CSV file, and this is my code</p>
  
  <pre><code>function varargout = signatureGUI(varargin)   
  % Begin initialization code - DO NOT EDIT
  gui_Singleton = 1;
  gui_State = struct('gui_Name',       mfilename, ...
                 'gui_Singleton',  gui_Singleton, ...
                 'gui_OpeningFcn', @signatureGUI_OpeningFcn, ...
                 'gui_OutputFcn',  @signatureGUI_OutputFcn, ...
                 'gui_LayoutFcn',  [] , ...
                 'gui_Callback',   []);
  if nargin &amp;&amp; ischar(varargin{1})
  gui_State.gui_Callback = str2func(varargin{1});
  end
  
  if nargout
      [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  else
  gui_mainfcn(gui_State, varargin{:});
  end
  % End initialization code - DO NOT EDIT
  
  
  
  % --- Executes just before signatureGUI is made visible.
  function signatureGUI_OpeningFcn(hObject, eventdata, handles, varargin)
  
  handles.output = hObject;
  handles.filename = 0;
  
  guidata(hObject, handles);
  
  
  
  % --- Outputs from this function are returned to the command line.
  function varargout = signatureGUI_OutputFcn(hObject, eventdata, handles) 
  
  varargout{1} = handles.output;
  
  
  
  % --- Executes on button press in browsefile.
  function browsefile_Callback(hObject, eventdata, handles)
  
  filename = uigetfile({'*.jpg'; '*.jpeg'; '*.png'});
  
  handles.filename=filename;
  guidata(hObject, handles);
  
  set(handles.showfile, 'String',filename );
  
  
  
  % --- Executes on button press in buttonwritecsv.
  function buttonwritecsv_Callback(hObject, eventdata, handles)
  
  handles.filename;
  
      new = imread (filename);
      newrgb=rgb2gray(new);
      newrgb_io = binz(newrgb);
  
      [filecsv,pathcsv] = uiputfile('*.csv','Save CSV File');
      csvwrite([filecsv,pathcsv], newrgb_io);
  
  guidata(hObject, handles);
  </code></pre>
  
  <p>I'm trying to use the " handles.filename " to let the Save As button able to get the variable from the Browse button, but when I click on the Save As button after browse for the file, it do nothing...</p>
  
  <p>Am I missing something or making mistake in using it?</p>
  
  <p>After I follow the answer from @Richante I got this following error, which I dont understand</p>
  
  <pre><code>??? Reference to non-existent field 'output'.
  
  Error in ==&gt; signatureGUI&gt;signatureGUI_OutputFcn at 34
  varargout{1} = handles.output;
  
  Error in ==&gt; gui_mainfcn at 265
          feval(gui_State.gui_OutputFcn, gui_hFigure, [],
          gui_Handles);
  
  Error in ==&gt; signatureGUI at 17
      gui_mainfcn(gui_State, varargin{:});
  </code></pre>
  
  <p>I dont know what is it..</p>