Skip to content
Snippets Groups Projects
Commit 4623ecd9 authored by Antoine Cyril David Hoffmann's avatar Antoine Cyril David Hoffmann :seedling:
Browse files

small function to compute averages and errors

parent 0256e6d1
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment