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: VBA_inv.m
    path of file: ./repos/PsPM/src/ext/VBA
    
    the code of the file until where you have to start completion: function [iQ] = VBA_inv(Q,indIn,flag,v)
% overloaded sparse matrix pseudo-inverse
% function [iQ] = VBA_inv(Q,indIn,flag,v)
% IN:

    
function [iQ] = VBA_inv(Q,indIn,flag,v)
% overloaded sparse matrix pseudo-inverse
% function [iQ] = VBA_inv(Q,indIn,flag,v)
% IN:
%   - Q: the nxn matrix to be inverted
%   - indIn: a vector of indices that specifies the submatrix of Q that has
%   to be inverted. The rest of the matrix is padded with zeros. If empty,
%   the routine looks for infinite or below precision (close to zero)
%   entries in the the diagonal of Q.
%   - flag: if flag='replace', the routine returns Q, having replaced its
%   elements not in 'indIn' with v (see below)
%   - v: a number by which to padd the elements of Q not in 'indIn' (only
%   for flag='replace')
% OUT:
%   - iQ: the nxn matrix that is either the inverse of Q or v-padded Q (for
%   flag='replace').

if nargin < 2 || isempty(indIn)
    dq = diag(Q);
    indIn = find(~isinf(dq)&dq~=0);
end