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: plot_entropy.m
    path of file: ./repos/OPEN_FPE_IFT/.previousVersions/V4 Functions
    
    the code of the file until where you have to start completion: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function plots the empirical average $\langle e^{\mathrm{-}\Delta S_{tot}} \rangle_N$ of 
% $\Delta S_{tot}$ as a function of the number, $N$ (sample size), of cascade trajectories 
% $\left[u(\cdot) \right]$ with errorbars. In addtion, the probability density function of the system, 
% medium and total entropy will be plotted while displaying the value of $\langle\Delta S_{tot}\rangle$ 
% which should be $\geq$ 0. The  integral fluctuation theorem (IFT) expresses the integral balance 
% between the entropy-consuming ($\Delta S_{tot}<0$) and the entropy-producing ($\Delta S_{tot}>0$) 
% cascade trajectories
% 
% Arguments IN
% Sm = Entropy of the medium
% Ds = Entropy of the system or the Shanon entropy
% DS = Total entropy production=Sm+Ds
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_entropy(Sm,Ds,DS,increment_bin,save_path)
set(groot, 'defaultAxesTickLabelInterpreter','latex'); 
set(groot, 'defaulttextinterpreter','latex');   
set(groot, 'defaultLegendInterpreter','latex');
set(groot, 'defaultAxesTitle','latex');


N               = size(DS,1);   % number of trajectories u(r)
NN              = 20;           % steps for the calculation of mean 
    
function plots the empirical average $\langle e^{\mathrm{-}\Delta S_{tot}} \rangle_N$ of 
% $\Delta S_{tot}$ as a function of the number, $N$ (sample size), of cascade trajectories 
% $\left[u(\cdot) \right]$ with errorbars. In addtion, the probability density function of the system, 
% medium and total entropy will be plotted while displaying the value of $\langle\Delta S_{tot}\rangle$ 
% which should be $\geq$ 0. The  integral fluctuation theorem (IFT) expresses the integral balance 
% between the entropy-consuming ($\Delta S_{tot}<0$) and the entropy-producing ($\Delta S_{tot}>0$) 
% cascade trajectories
% 
% Arguments IN
% Sm = Entropy of the medium
% Ds = Entropy of the system or the Shanon entropy
% DS = Total entropy production=Sm+Ds
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_entropy(Sm,Ds,DS,increment_bin,save_path)
set(groot, 'defaultAxesTickLabelInterpreter','latex'); 
set(groot, 'defaulttextinterpreter','latex');   
set(groot, 'defaultLegendInterpreter','latex');
set(groot, 'defaultAxesTitle','latex');


N               = size(DS,1);   % number of trajectories u(r)
NN              = 20;           % steps for the calculation of mean and std value
Nvec            = round(logspace(1,log10(N),NN));
FTvec           = nan(1,NN);
FTvec_err       = nan(1,NN);
FTvec_med       = nan(1,NN);
FTvec_err_med   = nan(1,NN);
FTvec_sys       = nan(1,NN);
FTvec_err_sys   = nan(1,NN);

for n=1:NN
    FTvec(n)            = nanmean( exp( -DS(1:Nvec(n)) ) );
%   FTvec(n)            = median( exp( -DS(1:Nvec(n)) ) );
    FTvec_err(n)        = nanstd( exp( -DS(1:Nvec(n)) ) )/sqrt(Nvec(n));
    
    FTvec_med(n)        = nanmean( exp( -Sm(1:Nvec(n)) ) );
    FTvec_err_med(n)    = nanstd( exp( -Sm(1:Nvec(n)) ) )/sqrt(Nvec(n));
    
    FTvec_sys(n)        = nanmean( exp( -Ds(1:Nvec(n)) ) );
    FTvec_err_sys(n)    = nanstd( exp( -Ds(1:Nvec(n)) ) )/sqrt(Nvec(n));
end