0

Can anyone explain me why the code below doesnt work and returns me

W = [.34 .34 ];
DG = sparse([1 2],[2 3],W);

UG = tril(DG + DG')

??? Error using ==> plus Matrix dimensions must agree.

and the code below works properly ?

W = [.34 .34 .34];
DG = sparse([1 2 3],[2 3 1],W);
UG = tril(DG + DG')
BenMorel
  • 34,448
  • 50
  • 182
  • 322
hoya21
  • 893
  • 7
  • 24

1 Answers1

1

In the first example, the size of DG is 2 by 3 and therefore adding DG and DG' will cause an matrix dimension error. In the second example the matrix DG is 3 by 3, hence no error when adding DG + DG'.

H.Muster
  • 9,297
  • 1
  • 35
  • 46
  • Thanks! I observed that this only works if the max element of two vectors exists both to the first and the second vector. – hoya21 Jan 11 '14 at 18:23