help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strict monotonic X-Values (filter duplicate entries)


From: Stefan Pofahl
Subject: Strict monotonic X-Values (filter duplicate entries)
Date: Tue, 10 Feb 2009 18:09:39 +0100

Hello,

I wonder, if there is a function to chance a vector into a strict
monotonic vector.
I found nothing, so I wrote my on routine (see below).
If there is more elegant way, it would be fine, if someone can tell me.

Regards,

Stefan

-- 
Tel.: 0731-3805149
Ochsensteige 48
89075 Ulm

=============================================================


function my_test()
  printf("1.) 
------------------------------------------------------------------\n")
  x_in = [1,2,3,4,3,5,7]
  sorted_x = sort(x_in)

  [x, ix] = monotonic(x_in)
  x_in(ix)

endfunction

function [x, ix ] = monotonic (x_in)
# to be strict monotonic the vector has to be sorted and we don't want
double values
# sx = sorted x, xnd = x with no duplicates
  [sx, isx] = sort(x_in);
# check if there are duplicate entries and if so eliminate them
  if (is_duplicate_entry(sx) != 0)
    ix = repmat(1,1,max(size(sx)));
    xnd = repmat(1,1,max(size(sx)));
    for i = 1:max(size(sx))
      ix(i) = i;
    endfor
    ii = 0;
    for i = 1:max(size(sx))
      xnd(ii+1) = sx(i);
      if (is_duplicate_entry(xnd(1:ii+1)) == 0)
        ii++;
        # Indices may have changed after sorting
        ix(ii) = isx(i);
        xnd(ii) = sx(i);
      endif
    endfor
    ix = ix(1:ii);
    x = xnd(1:ii);
  else
    ix = isx;
    x = sx;
  endif

endfunction


reply via email to

[Prev in Thread] Current Thread [Next in Thread]