I want to find the inverse of an upper triangular matrix in an efficient way. I googled a lot, but all the articles discussed about a lower triangular matrix.
Is it possible to edit the matlab code in this answer so that its suitable for an upper triangular matrix? https://stackoverflow.com/a/12240951/919177
If you really want to find the inverse $M$ of an invertible upper triangular matrix $U$, note that $U M = I \implies M^T U^T = I$, which shows that $M^T$ is the inverse of the lower triangular matrix $U^T$.
So, you can find $M^T$ using the code you already have to invert a lower triangular matrix. This gives you $M$.
However, a rule of thumb is that you rarely want to compute the inverse of a matrix explicitly. If you ever need to solve $Ux = b$, you can just use back substitution.