function [res,hCart, hIner, hVis, hBoht] = function_calculateKalmanOptimization(data, exp_nbr, kalmanConfiguration, showImage, subPlots,legendFont)
    % Creates a function handle to call different function based on a string
    fh = str2func(sprintf('CONFIG_DATA_%d', exp_nbr));
    config = fh();
    load('../01 GetVariableUsableData/InertialCart.mat')
    if(exp_nbr == 1); cart = cart1; elseif(exp_nbr == 2); cart = cart2; end
    
    % Creation of Kalman Filter Variable (for both values)
    KalmanAcelFalsi = function_KalmanFilter(data,'i',false, kalmanConfiguration);
    KalmanAcelFalsv = function_KalmanFilter(data,'v',false, kalmanConfiguration);
    KalmanAcelFalsb = function_KalmanFilter(data,'b',false, kalmanConfiguration);
    KalmanAcelTruei = function_KalmanFilter(data,'i', true, kalmanConfiguration);
    KalmanAcelTruev = function_KalmanFilter(data,'v', true, kalmanConfiguration);
    KalmanAcelTrueb = function_KalmanFilter(data,'b', true, kalmanConfiguration);
    
    
    if(true)
        load('../01 GetVariableUsableData/InertialCart.mat')
        axis on; grid on; axis([KalmanAcelFalsi(1,1) KalmanAcelFalsi(end,1) -120 120]); hold on;
        plot(           data(:,1),            data(:,3),'-r');
            indx = find(data(:,8)==-60140);
            data(indx,:) = [];
        plot(           data(:,1),            data(:,8),'-g');
        plot(KalmanAcelFalsi(:,1), KalmanAcelFalsi(:,3),'-.r');
        plot(KalmanAcelFalsv(:,1), KalmanAcelFalsv(:,3),'-.g');
        plot(KalmanAcelFalsb(:,1), KalmanAcelFalsb(:,3),'-.b');
        plot(KalmanAcelTruei(:,1), KalmanAcelTruei(:,3),'--r');
        plot(KalmanAcelTruev(:,1), KalmanAcelTruev(:,3),'--g');
        plot(KalmanAcelTrueb(:,1), KalmanAcelTrueb(:,3),'--b');
%         plot(          cart1(:,1),           cart1(:,2), '-k','LineWidth',1.5);
        plot(          cart2(:,1),           cart2(:,2), '-k','LineWidth',1.5);
        xlabel('t(s)'); ylabel('\theta(º)');
        legend('Inertial Raw','Visual Raw','KF Inertial (=0)','KF Visual (=0)','KF Both (=0)','KF Inertial (!0)','KF Visual (!0)','KF Both (!0)','Ground Truth')
        pause
        close all
    end
    
    % Compare Results
    res(1,:) = function_compareResults(cart, data(:,[1 3]));            % Filt Comparison
    res(3,:) = function_compareResults(cart, KalmanAcelFalsi(:,[1 3])); % Kalman Non-Accel i
    res(4,:) = function_compareResults(cart, KalmanAcelFalsv(:,[1 3])); % Kalman Non-Accel v
    res(5,:) = function_compareResults(cart, KalmanAcelFalsb(:,[1 3])); % Kalman Non-Accel b
    res(6,:) = function_compareResults(cart, KalmanAcelTruei(:,[1 3])); % Kalman Acceleration i
    res(7,:) = function_compareResults(cart, KalmanAcelTruev(:,[1 3])); % Kalman Acceleration v
    res(8,:) = function_compareResults(cart, KalmanAcelTrueb(:,[1 3])); % Kalman Acceleration b
    
    % Compare the average data from visual acquisition
    a = 0;
    AverageVisualResults = zeros(size(data,1), 2);
    values = [0 0 0];
    for i = 8:2:size(data,2)
        a = a + 1;
        temp = function_compareResults(cart, data(:,[1 i]));           % Visual Comparison
        AverageVisualResults = AverageVisualResults + data(:,[1 i]);
        values = values + temp;
    end
    res(2,:)             =               values/a;
    AverageVisualResults = AverageVisualResults/a;
    
    
    % Delete all rows with -60140
    Condition = AverageVisualResults(:,2) == -60140;
    AverageVisualResults(Condition,:) = [];
end