You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: savestruct.m
    path of file: ./repos/bspm/thirdparty/spm12/toolbox/marsbar-0.44/@mardo
    
    the code of the file until where you have to start completion: function savestruct(obj, filename)
% saves data in def_struct as variables in .mat file
% FORMAT savestruct(object, matname)  
%
% $Id$
  
if nargin ~= 2
  error('Need matfile name');
end

    
function savestruct(obj, filename)
% saves data in def_struct as variables in .mat file
% FORMAT savestruct(object, matname)  
%
% $Id$
  
if nargin ~= 2
  error('Need matfile name');
end

% allow args to be in reverse order
if ischar(obj)
  tmp = obj;
  obj = filename;
  filename = tmp;
end

% Convert vols to native format
obj = convert_vols(obj, native_vol_ver(obj));

% unobjectify marsy object before save
SPM = des_struct(obj);
if isfield(SPM, 'marsY')
  SPM.marsY = y_struct(SPM.marsY);
end