function ltpdv_save_objects(varargin)

% Handles
myh     = varargin{1};
mainfig = varargin{end};

% Get selected objects
objs = ltpdv_get_selected_objs(mainfig);

% Get filename from user
[filename, pathname] = uiputfile( ...
  {'*.mat','MAT-files (*.mat)'; ...
  '*.xml','LTPDA-XML-files (*.xml)'}, ...
  'Save as')


if isequal(filename,0) || isequal(pathname,0)
  disp('Cancelled.')
else
  fname = fullfile(pathname, filename);
  % split filename up
  [pathstr, name, ext] = fileparts(fname);
  
  switch ext
    case '.mat'
      
      save(objs, fname);
      
    case '.xml'
      
      
      % Save each object
      for j=1:numel(objs)

        obj = objs{j};
        
        % filename
        fname = fullfile(pathstr, sprintf('%s_%03d%s', name, j, ext));
        
        % save object
        save(obj, fname)

      end

    otherwise
      error('### Unsupported file format.');
  end
  
  
  
end





% END