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: bst_opticalflow_states.m
    path of file: ./repos/brainstorm3/toolbox/math
    
    the code of the file until where you have to start completion: function [stable, transient, stablePoints, transientPoints, dEnergy] = ...
      bst_opticalflow_states(flowField, Faces, Vertices, dimension, interval, samplingInterval, displayFlag)
% BST_OPTICALFLOW_STATES  Computation of stable and transition states for
%                         optical flow (i.e. points where flow is strongest
%                         and weakest).
% INPUTS:
%   flowField           - Optical flow displacment field
%   Faces               - Faces of tesselation
%   Vertices            - Vertices of tesselation
%   dimension           - 3 for reconstructions, 2 for projections
%   interval            - time points for which flow is calculated
%   samplingInterval    - time between two samples, used to remove
%                         fake microstates (with duration < 5ms)
%   displayFlag         - flag to display displacement energy with time
%                             points labeled if they are part of a stable
%                             or transition state
% OUTPUTS:
%   stable              - List where each row is a 2-element pair
%                         containing the start and stop of a stable state
%   transient           - List where each row is a 2-element pair
%                         containing the start and stop of a fast state
%   stablePoints        - All times during which flow is "stable"
%   transientPoints     - All times during which flow is "fast"
%   dEnergy             - displacement energy in flow

% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
% 
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
% 
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@

% Setup: get displacement energy
[syed, triangleAreas] = geometry_tesselation(Faces, Vertices, dimension);
dEnergy = zeros(1, size(flowField,3));
for m = 1:size(flowField,3);
  v12 = sum((flowField(Faces(:,1),:,m)+flowField(Faces(:,2),:,m)).^2,2) / 4;

    
function [stable, transient, stablePoints, transientPoints, dEnergy] = ...
      bst_opticalflow_states(flowField, Faces, Vertices, dimension, interval, samplingInterval, displayFlag)
% BST_OPTICALFLOW_STATES  Computation of stable and transition states for
%                         optical flow (i.e. points where flow is strongest
%                         and weakest).
% INPUTS:
%   flowField           - Optical flow displacment field
%   Faces               - Faces of tesselation
%   Vertices            - Vertices of tesselation
%   dimension           - 3 for reconstructions, 2 for projections
%   interval            - time points for which flow is calculated
%   samplingInterval    - time between two samples, used to remove
%                         fake microstates (with duration < 5ms)
%   displayFlag         - flag to display displacement energy with time
%                             points labeled if they are part of a stable
%                             or transition state
% OUTPUTS:
%   stable              - List where each row is a 2-element pair
%                         containing the start and stop of a stable state
%   transient           - List where each row is a 2-element pair
%                         containing the start and stop of a fast state
%   stablePoints        - All times during which flow is "stable"
%   transientPoints     - All times during which flow is "fast"
%   dEnergy             - displacement energy in flow

% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
% 
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
% 
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@

% Setup: get displacement energy
[syed, triangleAreas] = geometry_tesselation(Faces, Vertices, dimension);
dEnergy = zeros(1, size(flowField,3));
for m = 1:size(flowField,3);
  v12 = sum((flowField(Faces(:,1),:,m)+flowField(Faces(:,2),:,m)).^2,2) / 4;
  v23 = sum((flowField(Faces(:,2),:,m)+flowField(Faces(:,3),:,m)).^2,2) / 4;
  v13 = sum((flowField(Faces(:,1),:,m)+flowField(Faces(:,3),:,m)).^2,2) / 4;
  dEnergy(m) = sum(triangleAreas.*(v12+v23+v13));
end