title: imwrite current image on axes in MATLAB GUIDE
body: <p>I have a problem in my GUI. In my opening function I defined an <code>img_new</code> variable to be an image I have stored.</p>
  
  <p>My GUI has two axes, one displays the original image and the other one the filtered one. I have 4 filters in a panel with the 4 radiobuttons. And in the end of each one's code there's the <code>img_new</code> = the image created through the radiobutton filter.</p>
  
  <p>Here's some code:</p>
  
  <pre><code>% --- Executes when selected object is changed in uipanel3.
  function uipanel3_SelectionChangeFcn(hObject, eventdata, handles)
  handles.count = handles.count + 1;
  
  % Change filter orientation depending on which radiobutton is chosen
  switch get(eventdata.NewValue,'Tag')
      case 'hte'
          h_te = zeros(handles.rows, handles.colums);
  
          # code of the filter...
  
          axes(handles.axes2);
          imshow(h_te);
  
          handles.img_new = h_te;
  
      case 'hc'
          h_c = zeros(handles.rows, handles.colums);
  
          # code of the filter...
  
  
          axes(handles.axes2);
          imshow(h_c);
  
          handles.img_new = h_c;
  
      case 'vlr'
          v_lr = zeros(handles.rows, handles.colums);
  
          # code of the filter...
  
  
          axes(handles.axes2);
          imshow(v_lr);
  
          handles.img_new = v_lr;
  
      case 'vc'
          v_c = zeros(handles.rows, handles.colums);
  
          # code of the filter...
  
          axes(handles.axes2);
          imshow(v_c);
  
          handles.img_new = v_c;
  
  end
  guidata(hObject, handles)
  </code></pre>
  
  <p>and here's the <code>imwrite</code> function:</p>
  
  <pre><code>% --------------------------------------------------------------------
  function save_img_ClickedCallback(hObject, ~, handles)
  % writing the new image
  imwrite(handles.img_new, strcat('filtered_image_', num2str(handles.count), '.png'));
  guidata(hObject, handles)
  </code></pre>
  
  <p>Here's the function to get the image to <code>axes1</code>  the original) and filter it to <code>axes2</code> (filtered)</p>
  
  <pre><code>% --- Executes on button press in img2.
  function img2_Callback(hObject, ~, handles)
  % Read image 2
  img = imread('./coimbra_estadio.jpg');
  handles.img_d = im2double(img);
  
  % image size
  size_img = size(handles.img_d);
  handles.colums = size_img(2);
  handles.rows = size_img(1);
  
  if rem(handles.rows,2) == 0
      handles.row_0 = ((handles.rows/2)+1);
  else
      handles.row_0 = ((handles.rows/2)+0.5);
  end
  
  if rem(handles.colums,2) == 0
      handles.colum_0 = ((handles.colums/2)+1);
  else
      handles.colum_0 = ((handles.colums/2)+0.5);
  end
  
  axes(handles.axes1);
  imshow(img);
  
  % Generate eventdata to call the radiobuttons function
  eventdata_new.EventName = 'SelectionChanged';
  eventdata_new.OldValue = get(handles.uipanel3,'SelectedObject');
  eventdata_new.NewValue = get(handles.uipanel3,'SelectedObject');
  
  uipanel3_SelectionChangeFcn(handles.uipanel3, eventdata_new, handles);
  guidata(hObject, handles)
  </code></pre>
  
  <p>As you can see, in the end I call the panel function so when the image is loaded it is automatically filtered and the <code>axes2</code> image changes.</p>
  
  <p>The problem is when I call the save function it saves the old <code>img_new</code>.</p>
  
  <p>If I change the radiobutton the <code>img_new</code> is refreshed, but if it is not changed it is not refreshed. It should be as loading an image automatically calls for the panel of radiobuttons function.</p>