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: sort_matrix.m
    path of file: ./repos/malini/Codes/FC_EC_calculation code/DynamicFC/jplv7/util
    
    the code of the file until where you have to start completion: function out = sort_matrix(key1,key2,matrix)
% PURPOSE: sort matrix using ID keys
% ---------------------------------------------------------
% USAGE: sorted = sort_matrix(key1,key2,matrix)

    
function out = sort_matrix(key1,key2,matrix)
% PURPOSE: sort matrix using ID keys
% ---------------------------------------------------------
% USAGE: sorted = sort_matrix(key1,key2,matrix)
% where: key1 = the results matrix key, nobs x 1
%        key2 is a key for input matrix, nobs x 1
%        matrix = nobs by nvars input matrix
% RETURNS:
% sorted = a matrix arranged according to key1
%                nobs by nvars 
%                where matrix has been sorted by key1
% ---------------------------------------------------------

if nargin ~= 3
        error('sort_matrix: requires 3 input arguments');
end