# Why normalize function has a different result on a matrix vs single value?

I have a matrix like:

B=[ 1.5035; 1.5728; 1.6485;  1.5369;  1.5467;  1.572; 1.5374;  1.787;  1.5825; 1.6905];


Using normalize function like normalize(B,'range') has this result:

ans =  0
0.24444
0.51146
0.11781
0.15238
0.24162
0.11958
1
0.27866
0.65961


But when I use it for a single value like:

normalize(B(2,:),'range')


the result is 0 , but the result for row number 2 in ans is 0.24444. Why its different and how can I fix it?

The normalize function works by calculating z-score for the given data. Now z-score is given by: $$z_{i} = \frac{x_{i} - mean(X)}{s.d.(X)}$$ where $$X$$ is your original vector/matrix.
Now, when you give a vector as input it first calculates the mean and standard deviation for the row/column. Then the output you ask for is calculated the above formula. So, if you only ask for a scalar it only shows one value. You can see in your example the normalized value(or z-score) is same for that particular position i.e. $$0.24444$$.