%% GENERAL INFORMATION
% This matlab script is link to the publication "AR-assisted timber
% drilling with smart retrofitted tools".
% Specifically to the section 3 : evaluation and performance.
% Author(s): J. Gamerro & A. Settimi.
% Date: June 2021.

%% SCRIPT INFORMATION
%---------
% Analysis of the drilling results according to the different drilling
% angles ranging from 30 to 90°.
% The main parameters studied are:
%   1/ the starting point error
%   2/ the orientation error
%   3/ the depth error
%   4/ the ending point error

%--------
% In section "1/ Load data and parameters", the raw data are imported
% and sorted in different tables depending on the parameters.
% ExpData = data from the experimental campaign

%--------
% In section "2/ Statistical evaluation", a statistical analysis of the
% main parameters is done (mean + standard deviation).
% stat = results table per main parameter.

%--------
% In section "3/ Error Boxplots", the error boxplot of each parameter can
% be found and will be automatically shown in different figures when the
% script is executed.

%% START DOCUMENT
clc;
close all;
clear all;

%% 1/ Load data and parameters
load('ExpData.mat');                    % Load data from the drilling experimental campaign

dmodelangle = ExpData{:,1};             % drilling angle variable ranging from 30 to 90°
startPtdeviation = ExpData{:,2};        % starting point error
Endpointdeviation = ExpData{:,3};       % ending point error
Depthdeviation = ExpData{:,4};          % depth error
Orientationdeviation = ExpData{:,5};    % orientation error

%% 2/ Statistical evaluation

stat = grpstats(ExpData,'dmodelangle',{'mean','std'});     % stastical evalutatoin per drilling angle (mean + standard deviation)
%writetable(stat,'Results.xlsx','Sheet',1,'Range','B1');   % uncomment for an excel export of the statiscal evaluation

%% 3/ Error Boxplots

% starting point error boxplot %
figure (01)
hold on;
boxplot(startPtdeviation,dmodelangle);
ylabel('deviation (mm)');
xlabel('drilling angle (°)');
title(['Sample results: starting point error']);
% saveas(gcf,'startPtdeviation.png');   % uncomment for an automatic export
% of the figure in png format
hold off;

% Orientation error boxplot %
figure (02)
hold on;
boxplot(Orientationdeviation,dmodelangle);
ylabel('deviation (°)');
xlabel('drilling angle (°)');
title(['Sample results: orientation error']);
%saveas(gcf,'Orientationdeviation.png');% uncomment for an automatic export
% of the figure in png format
hold off;

% Depth error boxplot %

figure (03)
hold on;
boxplot(Depthdeviation,dmodelangle);
ylabel('deviation (mm)');
xlabel('drilling angle (°)');
title(['Sample results: depth error']);
%saveas(gcf,'Depthdeviation.png'); % uncomment for an automatic export
% of the figure in png format
hold off;

% End point error boxplot % 
figure (04)
hold on;
boxplot(Endpointdeviation,dmodelangle);
ylabel('deviation (mm)');
xlabel('drilling angle (°)');
title(['Sample results: ending point error']);
%saveas(gcf,'Endpointdeviation.png'); % % uncomment for an automatic export
% of the figure in png format
hold off;

%% END DOCUMENT