Suppose we have to minimize a function $f(X,Y)-g(X,Y)$, where both the functions are convex. How can this be solved in matlab? Is there any tool to solve this in matlab?
There are a lot of optimization functions in Matlab. Which to choose depends on the functions $f$ and $g$. For example, you can try fminunc, especially if you know first or second derivatives, or fminsearch for a derivative-free method.
However, note that the difference of convex function is not in general a convex function, so you can get stuck in local minimum.