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: order_components.m
    path of file: ./repos/CaImAn-MATLAB/utilities
    
    the code of the file until where you have to start completion: function [srt,n_events,n_act] = order_components(YrA,C,sn,options)

% order components by how unlikely it is to produce the data under a no
% spiking hypothesis. The function counts how many times the trace is above
% the sum of the mode and a given number of standard deviations for a given
% number of consecutive intervals. 

% INPUTS

% YrA:      Noise for each temporal component
% C:        Temporal components
% sn:       Standard deviation of each component (optional, estimated if not given)
% options:  Options structure
%   options.nsd:    number of standard deviations to set threshold
%   options.nfr:    number of consecutive frames for considering an event

% OUPUTS

% srt:      Sorted components in decreasing order
% n_event:  Number of events for each components in decreasing order
% n_act:    Number of components with events (The srt(1:n_act) is the set of active components)

% Written by:
% Eftychios A. Pnevmatikakis, Simons Foundation, 2016

    
function [srt,n_events,n_act] = order_components(YrA,C,sn,options)

% order components by how unlikely it is to produce the data under a no
% spiking hypothesis. The function counts how many times the trace is above
% the sum of the mode and a given number of standard deviations for a given
% number of consecutive intervals. 

% INPUTS

% YrA:      Noise for each temporal component
% C:        Temporal components
% sn:       Standard deviation of each component (optional, estimated if not given)
% options:  Options structure
%   options.nsd:    number of standard deviations to set threshold
%   options.nfr:    number of consecutive frames for considering an event

% OUPUTS

% srt:      Sorted components in decreasing order
% n_event:  Number of events for each components in decreasing order
% n_act:    Number of components with events (The srt(1:n_act) is the set of active components)

% Written by:
% Eftychios A. Pnevmatikakis, Simons Foundation, 2016

if nargin < 3 || isempty(sn)
    sn = std(YrA,[],2);
end