1

I have a 3x55 matrix of ints. I want to center each row around its mean. This gets the right answer, but it's ugly:

row_mean = mean(points,[2])
points[1,:] = points[1,:] - row_mean[1]
points[2,:] = points[2,:] - row_mean[2]
points[3,:] = points[3,:] - row_mean[3]

Any ideas?

C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
ashley
  • 1,535
  • 1
  • 14
  • 19

1 Answers1

4

EDITED:

You can use the element-wise minus function, .-, to calculate the difference between each row and its mean value:

points .- mean(points, 2)
David P. Sanders
  • 5,210
  • 1
  • 23
  • 23
Reza Afzalan
  • 5,646
  • 3
  • 26
  • 44
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/10156839) – ElGavilan Nov 10 '15 at 13:25
  • @ElGavilan I have edited the answer to clear any request for clarification. – Reza Afzalan Nov 10 '15 at 14:11
  • 1
    It seems to me that it correctly provides an answer to the original question, – David P. Sanders Nov 11 '15 at 02:00
  • Thanks @RezaAfzalan that about did it. There seems to be some precision difference between the two answers though. Tiny like -2.32831e-10. Wondering what the difference is.. – ashley Nov 12 '15 at 11:51