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: sim_data.m
    path of file: ./repos/CanlabCore/CanlabCore/@fmri_data
    
    the code of the file until where you have to start completion: function [obj, true_obj, noise_obj] = sim_data(obj, varargin)
% Create simulated data and attach it to an fmri_data object (obj)
%
% :Usage:
% ::
%
%     obj = sim_data(obj, [optional inputs])
%
% For objects: Type methods(object_name) for a list of special commands
%              Type help object_name.method_name for help on specific
%              methods.
%
% ..
%     Author and copyright information:
%
%     Copyright (C) 2016 Tor Wager
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
% ..
%
% :Inputs:
%
%   **obj:**
%       an fmri_data object
%
% :Optional Inputs:
%
% **'n':**
%       Number of images/observations (e.g., subjects)
%
% **'d'**
%       Cohen's d for true regions
%
% **'true_region_mask'**
%       Followed by mask of which regions to add true signal
%       Default is the 'frontoparietal' network from Yeo et al. 2011
%
% **'noise_sigma'**
%       Followed by noise sigma (std) value
%
% **'smoothness'**
%       Followed by smoothing value (default = 5)
%
%
% :Outputs:
%
%   **obj:**
%        Object with simulated data, signal + noise
%        obj.additional_info{1} = structure with simulation PARAMS
%        obj.additional_info{2} = structure with SIGNAL calculations and indicators;
%
%
%   **true_obj:**
%        Signal data object
%
%   **noise_obj:**

    
function [obj, true_obj, noise_obj] = sim_data(obj, varargin)
% Create simulated data and attach it to an fmri_data object (obj)
%
% :Usage:
% ::
%
%     obj = sim_data(obj, [optional inputs])
%
% For objects: Type methods(object_name) for a list of special commands
%              Type help object_name.method_name for help on specific
%              methods.
%
% ..
%     Author and copyright information:
%
%     Copyright (C) 2016 Tor Wager
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
% ..
%
% :Inputs:
%
%   **obj:**
%       an fmri_data object
%
% :Optional Inputs:
%
% **'n':**
%       Number of images/observations (e.g., subjects)
%
% **'d'**
%       Cohen's d for true regions
%
% **'true_region_mask'**
%       Followed by mask of which regions to add true signal
%       Default is the 'frontoparietal' network from Yeo et al. 2011
%
% **'noise_sigma'**
%       Followed by noise sigma (std) value
%
% **'smoothness'**
%       Followed by smoothing value (default = 5)
%
%
% :Outputs:
%
%   **obj:**
%        Object with simulated data, signal + noise
%        obj.additional_info{1} = structure with simulation PARAMS
%        obj.additional_info{2} = structure with SIGNAL calculations and indicators;
%
%
%   **true_obj:**
%        Signal data object
%
%   **noise_obj:**
%        Noise data object
%
% :Examples:
% ::
%
% Create a simulated dataset with default values:
% [obj, true_obj, noise_obj] = sim_data(fmri_data);
%
% Create one with default values but 30 subjects:
%[obj, true_obj, noise_obj] = sim_data(fmri_data, 'n', 30);
%
% Display the mean true signal:
% [obj, true_obj, noise_obj] = sim_data(fmri_data, 'n', 30);
% o2 = canlab_results_fmridisplay([], 'compact2');
% o2 = addblobs(o2, region(mean(true_obj)), 'color', [0 0 1]);
%
% Show some summary information about the mean effects in true-signal and
% false-signal regions:
% obj.additional_info{2}
%
% Generate some data with true mean shift and true correlation with a
% simulated predictor, and show summary stats:
%
% N = 20;
% [obj, true_obj, noise_obj] = sim_data(fmri_data, 'n', N, 'r', .5);
% obj.additional_info{2}
%
% Generate some data no mean signal but a true correlation with a
% simulated predictor, and show summary stats:
%
% [obj, true_obj, noise_obj] = sim_data(fmri_data, 'n', N, 'd', 0, 'r', .5);
% obj.additional_info{2}
%
% Generate null data with no true signal, and show summary stats:
% Note: there is still a default mask with 'true' and 'false' regions, but
% effect sizes are zero.
% 
% [obj, true_obj, noise_obj] = sim_data(fmri_data, 'n', N, 'd', 0);
% OR:
% [obj, true_obj, noise_obj] = sim_data(fmri_data, 'n', N, 'null');
%
% Re-calculate the voxel-wise correlation with the outcome obj.Y:
% Uses a stored Anonymous Function handle to get vector-with-matrix correlation
% corr_matrix = obj.additional_info{1}.corr_matrix; 
% r = corr_matrix(obj.Y, obj.dat');
%
% :References:
%   None.
%
% :See also:
%   -
%
%
% ..
%    Programmers' notes:
%   Documentation and update, July 2016, Tor Wager
%   Update for simulations, Feb 2019
% ..

% -------------------------------------------------------------------------
% DEFAULTS AND INPUTS
% -------------------------------------------------------------------------

rng('shuffle');         % seeds the random number generator 

[v, n] = size(obj.dat); % voxels x imagess

true_region_mask = [];  % to use default mask
d = 0.5;                % Cohen's d for true regions (true effect size)
r = 0;                  % Correlation with outcome vector; individual diffs

noise_sigma = 1;        % Noise standard deviation (Gaussian)
smoothness = 5;         % Data smoothing

doplot = 0;

% optional inputs with default values
for i = 1:length(varargin)
    if ischar(varargin{i})
        switch varargin{i}
            
            case 'n', n = varargin{i+1}; varargin{i+1} = [];
            case 'd', d = varargin{i+1}; varargin{i+1} = [];
  
            case {'correlation', 'r'}, r = varargin{i+1}; varargin{i+1} = [];
                    
            case 'true_region_mask', true_region_mask = varargin{i+1}; varargin{i+1} = [];
            case 'noise_sigma', noise_sigma = varargin{i+1}; varargin{i+1} = [];
            case 'smoothness', smoothness = varargin{i+1}; varargin{i+1} = [];
                
            case 'null', d = 0; r = 0;
                
            case 'plot', doplot = 1;
                
            otherwise, warning(['Unknown input string option:' varargin{i}]);
        end