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_scout_value.m
    path of file: ./repos/brainstorm3/toolbox/math
    
    the code of the file until where you have to start completion: function [Fs, PcaFirstComp, HistoryMsg] = bst_scout_value(F, ScoutFunction, Orient, nComponents, XyzFunction, isSignFlip, ScoutName, Covar, PcaReference)
% BST_SCOUT_VALUE: Combine Ns time series using the given function. Used to get scouts/clusters values.
%
% USAGE:  Fs = bst_scout_value(F, ScoutFunction, Orient=[], nComponents=1, XyzFunction='none', isSignFlip=0, ScoutName=[], Covar=[], PcaReference=[])
%
% INPUTS:
%     - F             : [Nsources * Ncomponents, Ntime] double matrix, source time series
%     - ScoutFunc
    
function [F, explained] = PcaFirstMode(F, isLegacySign)
    % Signal decomposition / Remove average over time for each row
    FDemeaned = bsxfun(@minus, F, sum(F,2)./size(F,2));
    [U, S, V] = svd(FDemeaned, 'econ'); %sum(F,2)./size(F,2)
    S = diag(S);
    explained = [S(1).^2, sum(S.^2)];
    U = U(:,1);
    if isLegacySign
        % This section does not work properly: the resulting sign is arbitrary and leads to averaging issues.
        % Find which original signal has the largest coefficient in the first component
        [~, nmax] = max(abs(U));
        % What's the sign of absolute max amplitude in this signal?
        [~, i_omaxx] = max(abs(FDemeaned(nmax,:)));
        sign_omaxx = sign(FDemeaned(nmax,i_omaxx));
        % Sign of maximum in first component time series [at a different time - so unrelated actually]
        [~, i_Vmaxx] = max(abs(V(:,1)));
        sign_Vmaxx = sign(V(i_Vmaxx,1));
        % Reconcile signs
        CompSign = sign_Vmaxx * sign_omaxx;
    else
        % Remove ambiguity of arbitrary component sign for consistency across files/epochs and
        % reproducibility, as best we can here with single trial data.
        CompSign = nzsign(sum(U));
    end