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: msmforward.m
    path of file: ./repos/mdtoolbox/mdtoolbox
    
    the code of the file until where you have to start completion: function [logL, alpha, factor] = msmforward(data, T, emission, pi_i)
%% msmforward
% forward algorithm to calculate the probability of observed sequence
%
%% Syntax

    
function [logL, alpha, factor] = msmforward(data, T, emission, pi_i)
%% msmforward
% forward algorithm to calculate the probability of observed sequence
%
%% Syntax
%# [logL, alpha] = msmforward(data, T, emission, pi_i)
%# [logL, alpha, factor] = msmforward(data, T, emission, pi_i)
%
%% Description
% 
%
%% Example
%#
% 
%% See also
%
%% TODO
% robustness against zero elements of T
%

%% setup
if iscell(data)
  data_cell = data;
  is_cell   = true;
else
  data_cell{1} = data;
  is_cell      = false;
end