~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/statistics/center.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [s]=center(x,orient)
 
2
//
 
3
//This function  computes s,  the centered version  of the
 
4
//numerical matrix x.
 
5
//
 
6
//For a vector  or a matrix x, s=center(x)  returns in the
 
7
//(i,j)   coefficient   of   the   matrix  s   the   value
 
8
//(x(i,j)-xbar), where  xbar is the mean of  the values of
 
9
//the coefficients of x.
 
10
//
 
11
//s=center(x,'r') (or, equivalently, s=center(x,1)) is the
 
12
//rowwise center reduction of  the values of x. It returns
 
13
//in  the entry  s(i,j) the  value  (x(i,j)-xbarv(j)) with
 
14
//xbarv(j) the mean of the values of the j column.
 
15
//
 
16
//s=center(x,'c') (or, equivalently, s=center(x,2)) is the
 
17
//columnwise  centre reduction  of  the values  of x.   It
 
18
//returns in the  entry s(i,j) the value (x(i,j)-xbarh(i))
 
19
//with xbarh(i) the mean of the values of the i row.
 
20
//
 
21
//author: carlos klimann
 
22
//
 
23
//date: 2001-10-05
 
24
//
 
25
  if x==[] then s=%nan, return, end
 
26
  [lhs,rhs]=argn(0)
 
27
  if (rhs<1)|(rhs>2) then error('center requires one or two inputs.'), end
 
28
  [m n]=size(x);
 
29
  if rhs==1
 
30
    xbar=(sum(x)/(m*n))
 
31
    s=x-(ones(m,n)*xbar)
 
32
  elseif orient=='c'|orient==2 then
 
33
    xbar=sum(x,'c')/n
 
34
    s=x-(xbar*ones(1,n))
 
35
  elseif orient=='r'|orient==1 then
 
36
    xbar=sum(x,'r')/m
 
37
    s=x-(ones(m,1)*xbar)
 
38
  else error('Second center parameter must be r, c, 1 or 2'),
 
39
  end
 
40
endfunction