2
$\begingroup$

I have a 3 by 3 matrix, in which each element is a 2 by 1 matrix.

  1. How can I get rid of the zeros and change my matrix to a 3 by 3 matrix in which each element is a number?

  2. How can I keep the zeros and just change the 3 by 3 matrix to a 3 by 6 Matrix (get rid of the internal matrix forms and just keep the numbers)?

 {{{0., 0.0516705 Subscript[a, i, 1]}, {0., -0.0499662 Subscript[a, i, 2]}, 
   {0., 0.0189977 Subscript[a, i, 3]}}, 
  {{0., -0.0499662 Subscript[a, i, 1]}, {0., 0.0706682 Subscript[a, i, 2]}, 
   {0., -0.0539635 Subscript[a, i, 3]}}, 
  {{0., 0.0189977 Subscript[a, i, 1]}, {0., -0.0539635 Subscript[a, i, 2]}, 
   {0., 0.0741863 Subscript[a, i, 3]}}}
$\endgroup$
2
  • $\begingroup$ mat[[All, All, 2]], maybe. And look up ArrayReshape[mat, {3, 6}] to see if it does what you want. $\endgroup$ – Michael E2 Jun 10 '17 at 22:31
  • $\begingroup$ @MichaelE2 Thank you Michael, It works. :) $\endgroup$ – Delaram Nematollahi Jun 10 '17 at 22:53
1
$\begingroup$

This is record as an answer the solution given by MichaelE2 in a comment.

m =
  {{{0., 0.0516705 Subscript[a, i, 1]}, {0., -0.0499662 Subscript[a, i, 2]}, 
    {0., 0.0189977 Subscript[a, i, 3]}}, 
   {{0., -0.0499662 Subscript[a, i, 1]}, {0., 0.0706682 Subscript[a, i, 2]}, 
    {0., -0.0539635 Subscript[a, i, 3]}}, 
   {{0., 0.0189977 Subscript[a, i, 1]}, {0., -0.0539635 Subscript[a, i, 2]}, 
    {0., 0.0741863 Subscript[a, i, 3]}}};

m1 = m[[All, All, 2]]
{{0.0516705 Subscript[a, i, 1], -0.0499662 Subscript[a, i, 2], 
  0.0189977 Subscript[a, i, 3]}, 
 {-0.0499662 Subscript[a, i, 1], 0.0706682 Subscript[a, i, 2], 
  -0.0539635 Subscript[a, i, 3]}, 
 {0.0189977 Subscript[a, i, 1], -0.0539635 Subscript[a, i, 2], 
  0.0741863 Subscript[a, i, 3]}}
m2 = ArrayReshape[m, {3, 6}]
{{0., 0.0516705 Subscript[a, i, 1], 0., -0.0499662 Subscript[a, i, 2], 
  0., 0.0189977 Subscript[a, i, 3]}, 
 {0., -0.0499662 Subscript[a, i, 1], 0., 0.0706682 Subscript[a, i, 2], 
  0., -0.0539635 Subscript[a, i, 3]}, 
 {0., 0.0189977 Subscript[a, i, 1], 0., -0.0539635 Subscript[a, i, 2], 
  0., 0.0741863 Subscript[a, i, 3]}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.