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
You can use
repmatto make your average/std vector the same size as your original matrix, then use direct computation like so:Edit:
Judging from a mathworks blog post,
bsxfunsolution is faster and consumes less memory (see acai answer). For moderate size matrices, I personally prefer repmat that makes code easier to read and debug (for me).