function [indices, values] = closest(x, val)
    % Find the differences between the elements of x and the scalar value val
    diffs = abs(x - val);
    
    % Find the minimum difference
    [minDiff, minIndex] = min(diffs);
    
    % Find the indices of the elements of x that have the minimum difference
    indices = find(diffs == minDiff);
    
    % Extract the corresponding values of x at those indices
    values = x(indices);
end

