You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: globalAverageC.m
    path of file: ./repos/qups/kern
    
    the code of the file until where you have to start completion: function c_avg = globalAverageC(med, scan, pa, pb)
% GLOBALAVERAGEC - Global average sound speed between a set of points.
% 
% c_avg = GLOBALAVERAGEC(med, scan, pa, pb) returns the global average
% sound speed from the point pa to all points pb in the Medium med defined 
% on the ScanCartesian scan. The points pb and pa must all lie on the 2D
% X-Z plane. 
%
% Points outside of the scan are NaN.
%
% Example:
% 
% % Create a scan
% scan = ScanCartesian('x', linspace(-5, 5, 101), 'z', linspace(0, 40, 401));
% 
% % Create a simple layered sound speed distribution
% C = 1.5*ones(scan.size); % first layer
% C(scan.z > 20, :) = 1.6; % second layer
% C(scan.z > 30, :) = 1.4; % third layer
% 
% % Construct a Medium
% med = Medium.Sampled(scan, C); % create a medium
% med.c0 = 3.0; % ambient sound speed
% 
% % Compute the averege sound speed

    
function c_avg = globalAverageC(med, scan, pa, pb)
% GLOBALAVERAGEC - Global average sound speed between a set of points.
% 
% c_avg = GLOBALAVERAGEC(med, scan, pa, pb) returns the global average
% sound speed from the point pa to all points pb in the Medium med defined 
% on the ScanCartesian scan. The points pb and pa must all lie on the 2D
% X-Z plane. 
%
% Points outside of the scan are NaN.
%
% Example:
% 
% % Create a scan
% scan = ScanCartesian('x', linspace(-5, 5, 101), 'z', linspace(0, 40, 401));
% 
% % Create a simple layered sound speed distribution
% C = 1.5*ones(scan.size); % first layer
% C(scan.z > 20, :) = 1.6; % second layer
% C(scan.z > 30, :) = 1.4; % third layer
% 
% % Construct a Medium
% med = Medium.Sampled(scan, C); % create a medium
% med.c0 = 3.0; % ambient sound speed
% 
% % Compute the averege sound speed
% p_foc = [0;1] .* scan.z(:)'; % focal points
% c_avg = globalAverageC(med, scan, [0;0], p_foc);
%
% % Plot the average sound speed as a function of depth
% figure;
% subplot(1,2,1);
% imagesc(med, scan, 'props', 'c');
% subplot(1,2,2);
% plot(p_foc(2,:), c_avg, '.-');
% grid on;
% grid minor;
% xlabel('Depth (mm)');
% ylabel('Sound Speed (mm/us)');
% title('Layered Model Average Sound Speed')
% view(90, 90);
% 
% See also RAYPATHS

arguments
    med (1,1) Medium
    scan (1,1) ScanCartesian 
    pa (2,1) {mustBeNumeric} % aperture positions in 2D
    pb (2,:) {mustBeNumeric} % end