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: get_clamp.m
    path of file: ./repos/AI-mag/resources/material_database/utils
    
    the code of the file until where you have to start completion: function data = get_clamp(data, range)
% Clamp a matrix with respect to a given range.
%
%    Parameters:
%        data (matrix): data (unclamped)
%        range (vector): vector containing the range
%
%    Returns:
%        data (matrix): data (clamped)
%
%    (c) 2019-2020, ETH Zurich, Power Electronic Systems Laboratory, T. Guillod

    
function data = get_clamp(data, range)
% Clamp a matrix with respect to a given range.
%
%    Parameters:
%        data (matrix): data (unclamped)
%        range (vector): vector containing the range
%
%    Returns:
%        data (matrix): data (clamped)
%
%    (c) 2019-2020, ETH Zurich, Power Electronic Systems Laboratory, T. Guillod

if isempty(range)
    % pass
elseif length(range)==2
    % get range
    v_max = max(range(:));
    v_min = min(range(:));
    
    % clamp
    idx = data>v_max;
    data(idx) = v_max;
    idx = data<v_min;
    data(idx) = v_min;
else
    error('invalid clamp range')
end