1
function [m] = tabul(X, order)
4
// This function computes the frequency of values of
5
// the components of a vector or matrix X of numbers or
8
// If X is a numerical vector or matrix then
9
// m is a two column matrix who contains in
10
// the first column the distinct values of X
11
// and in the other column the number of occurrences
12
// of those values (m(i,2) is the number of occurrences
15
// If X is a vector or matrix of strings, m is a list
16
// whose first member is a string vector composed with
17
// the distinct values of X and the second member is a
18
// vector whose components are the number of occurrences
19
// of those values ( m(i)(2) is the number of occurrences
20
// of the string m(i)(1) ).
22
// The optional parameter order must be "d" or "i"
23
// (by default order = "d") and it gives the order
24
// of the distinct vector values of X (first column
25
// or first part of m) :
26
// order = "d" means that these values are sorted
27
// in decreasing order
28
// = "i" means by increasing order
31
// Original version by Carlos Klimann
32
// This version by Jean-Sebastien Giet & Bruno Pincon
34
// date: 1999-04-09 (original version)
35
// 2003-Mars-26 (new version)
39
// is faster (by using no more loop)
40
// performs a complete check of the input arguments
41
// add the order option
42
// used gsort in place of sort : the sort function
43
// sorts strings vector not the usual way !
47
error(" tabul : 1 or 2 input argument(s) needed")
52
if typeX ~= 1 & typeX ~= 10 then
53
error(" tabul : 1st input argument must be a vector/matrix of numbers or strings")
55
if type(order) ~= 10 then
56
error(" tabul : 2d input argument (order) must be ""i"" or ""d""")
58
if order~="i" & order~="d" then
59
error(" tabul : 2d input argument (order) must be ""i"" or ""d""")
67
X = gsort(X,"g",order)
69
ind = [find(X(1:$-1)~=X(2:$)) n]
76
else // X (and so val) is a vector of strings