From 4623ecd98298a159e0229538a8f10a1f62469392 Mon Sep 17 00:00:00 2001
From: Antoine Hoffmann <antoine.hoffmann@epfl.ch>
Date: Sat, 30 Sep 2023 11:28:58 +0200
Subject: [PATCH] small function to compute averages and errors

---
 matlab/compute/sliceAverage.m | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 matlab/compute/sliceAverage.m

diff --git a/matlab/compute/sliceAverage.m b/matlab/compute/sliceAverage.m
new file mode 100644
index 00000000..88280fa5
--- /dev/null
+++ b/matlab/compute/sliceAverage.m
@@ -0,0 +1,26 @@
+function [fullAverage, sliceAverages, sliceErrors] = sliceAverage(inputArray, n)
+    if mod(length(inputArray), n) ~= 0
+        % If not divisible, take a subset of the array
+        subsetLength = floor(length(inputArray) / n) * n;
+        inputArray = inputArray(1:subsetLength);
+    end
+
+    % Reshape the array into n slices
+    slicedArray = reshape(inputArray, [], n);
+
+    % Calculate the average over the entire array
+    fullAverage = mean(inputArray);
+
+    % Calculate the average for each slice
+    sliceAverages = mean(slicedArray);
+
+    % Calculate the error between slice averages
+    sliceErrors = abs(sliceAverages - fullAverage);
+    
+    % % Display results
+    % disp(['Full Average: ' num2str(fullAverage)]);
+    % for i = 1:n
+    %     disp(['Slice ' num2str(i) ' Average: ' num2str(sliceAverages(i))]);
+    %     disp(['Error for Slice ' num2str(i) ': ' num2str(sliceErrors(i))]);
+    % end
+end
\ No newline at end of file
-- 
GitLab