Jon
Jon

Reputation: 345

Converting a sparse matrix into a smaller full matrix

Let's say I have

    A = [3 0 2; ...
         0 0 1; ...
         1 1 0]
    A = sparse(A);

The output of which is below:

    ans =

   (1,1)        3
   (3,1)        1
   (3,2)        1
   (1,3)        2
   (2,3)        1

Question: is there an easy command to generate the following vector?

   B = [1 1 3;3 1 1; 3 2 1; 1 3 2;2 3 1]

    ans =

         1     1     3
         3     1     1
         3     2     1
         1     3     2
         2     3     1

Upvotes: 0

Views: 56

Answers (1)

Shai
Shai

Reputation: 114786

Try

[ ii jj aij ] = find( A );
B = [ii(:) jj(:) aij(:)];

Upvotes: 5

Related Questions