Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

element wise operation - MATLAB

Tags:

matrix

matlab

I have a matrix in MATLAB, lets say:

a = [
  89  79  96  
  72  51  74  
  94  88  87  
  69  47  78
]

I want to subtract from each element the average of its column and divide by the column's standard deviation. How can I do it in a way which could be implemented to any other matrix without using loops.

thanks

like image 612
user552231 Avatar asked Apr 14 '26 16:04

user552231


1 Answers

If your version supports bsxfun (which is probably the case unless you have very old matlab version), you should use it, it's much faster than repmat, and consumes much less memory. You can just do: result = bsxfun(@rdivide,bsxfun(@minus,a,mean(a)),std(a))

like image 130
Yanshuai Cao Avatar answered Apr 16 '26 11:04

Yanshuai Cao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!