function [ refinedMesh ] = RefineMesh( coarseMesh, nRefine )
%REFINEMESH Insert more points into each subinterval of a mesh
%   refinedMesh = RefineMesh( coarseMesh, nRefine )
%                                         default nRefine = 4
    if nargin == 1,
        nRefine = 4;
    end
    n = length( coarseMesh );
    [m1,m2] = size( coarseMesh );
    h = diff( coarseMesh );
    refinedMesh = repmat( coarseMesh(1:end-1).', 1, nRefine );
    refinedMesh = (refinedMesh+(h.')*[0:nRefine-1]/nRefine).';
    refinedMesh = [refinedMesh(:);coarseMesh(end)]; % column vector
    if m1<m2,
        refinedMesh = refinedMesh.'; % row vector input ==> also output
    end
end

