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: Fit_Logit_allstim.m
    path of file: ./repos/CanlabCore/CanlabCore/HRF_Est_Toolbox2/Old_stuff/More_recent_old_stuff
    
    the code of the file until where you have to start completion: function [VM, hrf, fit, e, param] = Fit_Logit_allstim(V0,tc,TR, Run, T)
% Fit inverse logit function model to time course 
% Multi-stimulus case
%
% INPUT:
%
% V0 = initial parameters
% tc = time course
% TR = time resolution
% Run = stick function (one trial type per cell)
%
%
% OUTPUT:
%
% VM = estimated parameters
% hrf = estimated HRF
% C = SSE
% fit - fitted time course
% param - estimated height, time to peak and width for each HRF

    
function [VM, hrf, fit, e, param] = Fit_Logit_allstim(V0,tc,TR, Run, T)
% Fit inverse logit function model to time course 
% Multi-stimulus case
%
% INPUT:
%
% V0 = initial parameters
% tc = time course
% TR = time resolution
% Run = stick function (one trial type per cell)
%
%
% OUTPUT:
%
% VM = estimated parameters
% hrf = estimated HRF
% C = SSE
% fit - fitted time course
% param - estimated height, time to peak and width for each HRF


numstim = length(Run);
len = length(Run{1});
t=1:TR:T;

% Initial values
LB = [0.05, 1, 0, 0.05, 5, 0.05, 8];      % Previous Lower bounds for parameters
UB = [5, 10, 2.5, 2, 15, 2, 20];     

LB = repmat(LB, 1, numstim);
UB = repmat(UB, 1, numstim);
V0 = repmat(V0, 1, numstim);


% Find optimal values
options = optimset('MaxFunEvals',10000,'Maxiter',10000,'TolX', 1e-6, 'TolFun', 1e-6,'Display','off');
VM = fminsearchbnd(@cost_allstim, V0, LB,UB,options,t,tc,Run);


% Use optimal values to fit hemodynamic response functions
hrf =zeros(length(t),numstim);
fitt = zeros(len,numstim);
param = zeros(3,numstim);

for g = 1:numstim
    hrf(:,g) = Get_Logit(VM(g*7-6:g*7),t);                   % Calculate HRF estimate (fit, given theta)
    param(:,g) = get_parameters2(hrf(:,g),(1:length(t)));
end