1

I have two matrices, one with 1x153 double and the other with 153x512 double and I require to subtract them while it is not possible and gives me error that they have not same dimensions.

Any idea how to solve it plz?

Dan
  • 45,079
  • 17
  • 88
  • 157
Biju
  • 71
  • 1
  • 2
  • 8
  • possible duplicate of [How can I divide each row of a matrix by a fixed row?](http://stackoverflow.com/questions/4723824/how-can-i-divide-each-row-of-a-matrix-by-a-fixed-row) – Eitan T Aug 15 '13 at 08:52

1 Answers1

3

Use bsxfun:

A = rand(1,153);
B = rand(153,152);

bsxfun(@minus,A.', B);

Notice that I first transposed A as one dimension needs to match at least.

Dan
  • 45,079
  • 17
  • 88
  • 157
  • 2
    Watch out, `A` might be complex. Better use `.'` instead of `'`. – Luis Mendo Aug 15 '13 at 08:32
  • @LuisMendo OP did specify `double`, but added the `.` anyways – Dan Aug 15 '13 at 08:52
  • 2
    Complex values can either be double or single precision (symbolic values can also be complex). Complexity is a distinct attribute from the class (`class(1i)` returns `'double'`). That's why `isfloat` and `isreal` exist. – horchler Aug 15 '13 at 14:56