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: add_batch_noise_obs.m
    path of file: ./repos/lrslibrary/algorithms/td/RLRT/rpca
    
    the code of the file until where you have to start completion: function data = add_batch_noise_obs( dataname, obsPct, noisePct, mag, Nrep, data )
% obsPct = 5%, 10%, ..., 95%, 100%
% noisePct = 1%, 5%, 10%, ..., 45%
% mag = 1, 5
%
% Data structure:
% Observations are stored as vectors of linear indices.
% Noise values are stored as (value vector, index vector) pairs.
% Indices are linear indices.
% Each observation and noise % value has 5 random replicates.
% obs{i} = Nt x Nrep matrix of indices
% noise{i} = vector of length Nrep
% noise{i}(k).val(:,j) = value vector of kth replicate with j-th magnitude
% noise{i}(k).ind = index vector of kth replicate

    
function data = add_batch_noise_obs( dataname, obsPct, noisePct, mag, Nrep, data )
% obsPct = 5%, 10%, ..., 95%, 100%
% noisePct = 1%, 5%, 10%, ..., 45%
% mag = 1, 5
%
% Data structure:
% Observations are stored as vectors of linear indices.
% Noise values are stored as (value vector, index vector) pairs.
% Indices are linear indices.
% Each observation and noise % value has 5 random replicates.
% obs{i} = Nt x Nrep matrix of indices
% noise{i} = vector of length Nrep
% noise{i}(k).val(:,j) = value vector of kth replicate with j-th magnitude
% noise{i}(k).ind = index vector of kth replicate

% generate original tensor if not given in input
if ~exist( 'data', 'var' ) || isempty(data)
    data = gen_lowrank_tensor( [50 50 20], [5 5 5] );
end