title: a simple probability code in matlab
body: <p>I've written a basic code for probablity of some data.It works and gives me outputs, what I want to get.</p>
  
  <pre><code>A=[2 3 5 4 4 4 5 2 3 2 3]
      a=length(A);
      b=unique(A);
      for i=1:length(b)
          T(i)=sum(A(:)==b(i));
          prob(i)=T(i)./a;
  
      end
  </code></pre>
  
  <p>I can't understand how to use this code as a function. I saved the following code as M-file and called as prob(A) for any matrix, but it doesn't work. Could you please tell me my mistake?</p>
  
  <pre><code>function z=prob(A)
  a=length(A);
  b=unique(A);
  for i=1:length(b)
      T(i)=sum(A(:)==b(i));
      pr(i)=T(i)./a;
      z=pr(i);
  end
  return
      end
  </code></pre>