Extract matrices out of a symbolic matrix

4 views (last 30 days)
Let's assume I have a matrix which looks something like:
Mtx = [2,3*x;4*x^2,1]
Is it "symbolically" possible to get 3 matrices out of this, which look like:
Mtx1 = [2,0;0,1]
Mtx2 = [0,3*x;0,0]
Mtx3 = [0,0;4*x^2,0]
Is there a function, that can do this or should I do it manually?

Accepted Answer

Andrew Newell
Andrew Newell on 20 Apr 2017
Edited: Andrew Newell on 20 Apr 2017
It looks like you are trying to extract the diagonal, upper triangular and lower triangular parts of the matrix. These commands will do it for larger matrices as well:
Mtx1 = diag(diag(Mtx));
Mtx2 = triu(Mtx,1);
Mtx3 = tril(Mtx,-1);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!