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: resample_to_image_space.m
    path of file: ./repos/CanlabCore/CanlabCore/@fmri_mask_image
    
    the code of the file until where you have to start completion: function obj = resample_to_image_space(obj, sampleto, varargin)

    
function obj = resample_to_image_space(obj, sampleto, varargin)
% Resamples data in an fmri_mask_image object (obj) to the space of another
% image (e.g., a functional image, for data extraction)
% The volInfo field will be the same as the sampleto volume info.
% The mask will have zeros in obj.dat for out-of-mask voxels.
% THIS FUNCTION USES SCN_MAP_IMAGE AND REQUIRES THAT THE ORIGINAL IMAGE BE
% AVAILABLE ON DISK.  Multiple resamplings will break the function because
% the new space will be different from the original one on disk.  Use the
% more general resample_space.
%
% NOTE: Mask is *reloaded* from original data if space is remapped, and you
% cannot use manual thresholding of the mask. This is a feature of the
% map_to_image_space method and scn_map_image
%
% :Usage:
% ::
%
%     obj = resample_to_image_space(obj, sampleto <img name or image_vector object>)
%
% :Inputs:
%
%   **obj:**
%        must be an fmri_mask_image object
%   **sampleto:**
%        can be either:
%           1. An image name to sample to
%           2. Another fmri_mask_image object (but image must exist on path!)
%
% :Optional inputs:
%   **mask:**
%        Apply sampleto as mask so that only voxels in the sampleto mask
%        are retained in obj.dat.
%
% THIS FUNCTION WORKS, BUT IS DEPRECATED BECAUSE RESAMPLE_SPACE IS MORE
% GENERAL.  resample_space does not require the resampling of the original
% image from disk, which this does.  resample_space is slower, though.
% 
% See Also: resample_space, for a method that does not require images to
% exist on disk on the path.
%
% ..
%    Programmers' notes
%    Tor: July 2011: Edited because old version will apply mask when resampling
%    space. Edited default behavior to NOT mask with voxels only in sampleto
%    space.  This could cause bugs in other functions that need to be worked
%    out.  The optional argument 'mask' should produce the old default
%    behavior.
%
%    Oct 30, 2011: obj.dat field after sampling did not conform to standard,
%    because only in-mask voxels in volInfo were not selected.  This was
%    fixed.
% ..

switch class(sampleto)
    case {'char', 'string'}
        image_name_to_sample_to = sampleto;
        
        volInfo_to = iimg_read_img(sampleto, 2, 1, 1); % read data from file, first volume only
        
    case {'image_vector', 'fmri_data', 'fmri_mask_image', 'statistic_image'}
        
        if any(strmatch('space_defining_image_name', fieldnames(sampleto), 'exact')) && ~isempty(sampleto.space_defining_image_name)
            image_name_to_sample_to = sampleto.space_defining_image_name;
        else
            image_name_to_sample_to = sampleto.volInfo.fname;
        end