[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Finding non-unique strings in a cell array
From: |
Olaf Till |
Subject: |
Re: Finding non-unique strings in a cell array |
Date: |
Tue, 24 May 2011 13:58:08 +0200 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Tue, May 24, 2011 at 12:13:41PM +0100, Andy Buckle wrote:
> I have a feeling that I am overcomplicating. Is there a better way than this?
>
> >a={'a','b','1'}; cellfun(@(x)sum(strcmp(x,a))>1,a)
> ans =
>
> 0 0 0
>
> >a={'a','b','b'}; cellfun(@(x)sum(strcmp(x,a))>1,a)
> ans =
>
> 0 1 1
>
> --
> /* andy buckle */
Maybe this:
octave:1> t = {"a", "b", "a", "c", "c", "a"};
octave:2> [t, idx] = sort (t);
octave:3> tidx = strcmp (t(1:end-1), t(2:end));
octave:4> ttidx = [tidx, false] | [false, tidx];
octave:5> result = false (size (ttidx));
octave:6> result(idx) = ttidx
result =
1 0 1 1 1 1
Olaf