Problem converting matlab formula for relative frequency vector to mathematical formula I have the following matlab code:
range = 7;
vector = [1 2 3 3 5 6 7 5 4];
freq = zeros(1,range);

for i=1:range freq(i) = length(vector(vector==i))/length(vector); end

I'd like to transform it into a mathematical formula but need help with the numerator and the sequence.
This is my attempt:
$v = vector$
$m = range$
s should be the subset of v equal to the current integer
$f = \left|s \subseteq v | \right| / \left|{v}\right|$
and this also needs to include the sequence of all integers from:
$\{1,\ldots\,m\}$
I'm just not sure how to put it together.
 A: Let $\delta_i$ be the Kronecker delta operator.  Let $n$ represent the dimensionality of the vector and let $m$ represent the range.  Consider the $m \times n$ matrix:
$$ D_{m,n} = \frac{1}{n}\left( \begin{array}{cccc} \delta_1 & \delta_1 & \dots & \delta_1 \\ \delta_2 & \delta_2 & \dots & \delta_2 \\ \vdots & & \ddots & \vdots \\ \delta_m & \delta_m & \dots & \delta_m \end{array}\right) $$
Then $D_{m,n} \cdot v$ is the output you desire.  Let us look at an example for the values you stated:
$$ \begin{align} D_{m,n} \cdot v  & = \frac{1}{4}\left( \begin{array}{cccc} \delta_1 & \delta_1 & \delta_1 & \delta_1 \\ \delta_2 & \delta_2 & \delta_2 & \delta_2 \\ \delta_3 & \delta_3 & \delta_3 & \delta_3 \end{array}\right) \left(\begin{array}{c} 1 \\ 2 \\ 2\\ 3 \end{array}\right) \\ &=  \frac{1}{4}\left(\begin{array}{c} \delta_11 + \delta_1 2 + \delta_1 2+ \delta_1 3 \\ \delta_21 + \delta_2 2 + \delta_2 2+ \delta_2 3 \\ \delta_3 1 + \delta_3 2 + \delta_3 2+ \delta_3 3 \end{array}\right) \\ & =  \frac{1}{4} \left(\begin{array}{c} 1 + 0 + 0 + 0 \\ 0 + 1 + 1 + 0 \\ 0 + 0 + 0 + 1 \end{array}\right) \\& =  \frac{1}{4} \left(\begin{array}{c} 1 \\ 2 \\ 1 \end{array}\right)\end{align}$$
You can write this in a nicer way by:
$$ D_{m,n} \cdot v = \frac{1}{n}  \left(\begin{array}{c} \delta_1 \\ \delta_2 \\ \vdots \\ \delta_m \end{array}\right) \left(\begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \end{array}\right)^T v $$
but be careful you understand that this is just shorthand and you need to know when it's an operator action and when it's multiplication.
