octave-maintainers
[Top][All Lists]
Advanced

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

Cell support added to unique


From: Keith Goodman
Subject: Cell support added to unique
Date: Sat, 9 Apr 2005 14:17:35 -0500

Here's a patch that adds support for cell arrays of strings to the
octave-forge function unique.

I also fixed a typo in the documentation and replaced the deprecated
function setstr with char.


*** /usr/share/octave/site/m/octave-forge/set/unique.m  Sun Feb 27 07:02:24 2005
--- unique.m    Sat Apr  9 12:05:50 2005
***************
*** 28,34 ****
  ## @deftypefnx {Function File} address@hidden, @var{i}, @var{j}] = }
unique (@var{x})
  ##
  ## Return index vectors @var{i} and @var{j} such that @code{x(i)==y} and
! ## @code{y(i)==x}.
  ##
  ## @end deftypefn
  ## @seealso{union, intersect, setdiff, setxor, ismember}
--- 28,34 ----
  ## @deftypefnx {Function File} address@hidden, @var{i}, @var{j}] = }
unique (@var{x})
  ##
  ## Return index vectors @var{i} and @var{j} such that @code{x(i)==y} and
! ## @code{y(j)==x}.
  ##
  ## @end deftypefn
  ## @seealso{union, intersect, setdiff, setxor, ismember}
*************** function [y, i, j] = unique (x, r)
*** 58,70 ****

    if nargin == 2
      [y, i] = sortrows(y);
!     match = all( [ y(1:n-1,:) == y(2:n,:) ]' );
      idx = find (match);
      y (idx, :) = [];
    else
      if (size(y,1) != 1) y = y(:); endif
      [y, i] = sort(y);
!     match = [ y(1:n-1) == y(2:n) ];
      idx = find (match);
      y (idx) = [];
    endif
--- 58,78 ----

    if nargin == 2
      [y, i] = sortrows(y);
!     if iscell(x)
!       match = all( strcmp(y(1:n-1,:),y(2:n,:))' );
!     else
!       match = all( [ y(1:n-1,:) == y(2:n,:) ]' );
!     endif
      idx = find (match);
      y (idx, :) = [];
    else
      if (size(y,1) != 1) y = y(:); endif
      [y, i] = sort(y);
!     if iscell(x)
!       match = strcmp(y(1:n-1),y(2:n));
!     else
!       match = [ y(1:n-1) == y(2:n) ];
!     endif
      idx = find (match);
      y (idx) = [];
    endif
*************** function [y, i, j] = unique (x, r)
*** 77,83 ****
    endif
    i (idx) = [];

!   if isstr(x), y = setstr(y); endif

  endfunction

--- 85,91 ----
    endif
    i (idx) = [];

!   if isstr(x), y = char(y); endif

  endfunction

*************** endfunction
*** 88,90 ****
--- 96,100 ----
  %!assert(unique([1 2]),[1 2])
  %!assert(unique([1;2]),[1;2])
  %!assert(unique([1,NaN,Inf,NaN,Inf]),[1,Inf,NaN,NaN])
+ %!assert(unique({'ab' 'cd';'cd' 'ab'}),{'ab';'cd'})
+ %!assert(unique({'ab' 'cd';'cd' 'ab'},'rows'),{'ab' 'cd';'cd' 'ab'})



reply via email to

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