function [residuals, geoDistance] = calculateResiduals(calculatedPosition, calculatedDistances, soundsourcePositions, soundVelocities) %CALCULATEMISFITS Calculates % Detailed explanation goes here %% Initialize variables geoDistance = NaN(size(calculatedDistances)); residuals = NaN(size(calculatedDistances)); %% Parameter check if any(isnan(calculatedPosition)) return; end %% Calculate misfits for i = 1:length(soundsourcePositions) geoDistance(i) = artoa.data.calculateGeodist(soundsourcePositions, calculatedPosition); residuals(i) = (calculatedDistances(i) - geoDistance(i)) / soundVelocities{i + 1, 'AppliedSoundspeed'}; end end