Am Freitag, den 10.10.2008, 11:19 +0200 schrieb Paul Hussein:
> OK,
> 
> thanks for the reply. Maybe I am interpreting octave's output incorrectly.
> 
> when I call mad i get :
> 
> octave:1> mad([1234])
> usage: a = mad (X,dim)
> error: evaluating if command near line 23, column 3
> error: called from `mad' in file `/home/matlab/octave/statistics-1.0.7/mad.m'
> octave:1>
> 
> 
> 
> Why do I get 'error: evaluating if command near line 23, column 3'

The function is buggy (or rather, the argument check will always fail).

Try the attached function instead.

        Thomas
## Copyright (C) 2001 Paul Kienzle
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see <http://www.gnu.org/licenses/>.

## a = mad(X)
##    mean absolute deviation of X
function a = mad(X,dim)
  if nargin == 1
    dim = min(find(size(X)>1));
    if isempty(dim), dim=1; endif;
  endif
  if (!(nargin == 1 || nargin == 2))
    usage("a = mad (X,dim)");
  elseif (prod(size(X)) != size(X,dim))
    sz = ones(1,length(size(X)));
    sz(dim) = size(X,dim);
    a = nanmean (abs (X - repmat (nanmean (X, dim), sz)), dim);
  elseif all (size (X) > 1)
    a = nanmean (abs (X - ones(size(X,1),1) * nanmean(X, dim)), dim);
  else
    a = nanmean (abs (X - nanmean(X, dim)), dim);
  endif
endfunction
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to