1a
2b
3c
4d
5d
6f
6g
8h
Is there some function I can use to determine if there is a letter or number repeated in any element of this array? For example, in this there are 2 d's as well as 2 6's. So I need some way to check if there is a repeat in the first character of any element in this array as well as if there is a repeat in the second character of any element, and then produce a 1x1 logical vector with a 1 if there are no repeats and a 0 if there are any repeats of a letter and/or a number. The array above would return a 0. However:
1a
2b
3c
4d
5e
6f
7g
8h
would return a 1, because there is neither a repeated letter or a repeated number. Theoretically I could see if the number of element 1 equals that in elements 2, 3, 4, etc. and then repeat for the rest of the numbers as well as letters but that would be a ridiculous number of lines of code. :p
Basically,
u=unique(char(arry(:)));
will give the components of the array. Then for each if
sum(find(..)) > 1
the answer is there is a duplicate.
Thinking about that may lead to some shortcuts; didn't spend much time...
--
One thing came to mind -- not sure otomh how to string all the
characters in the cell array into -- oh, this'll do it if the cell array
is c:
ch=char(c);ch=ch(:)+0; % convert to numeric vector
flg = all(diff(sort(ch)));
% if no repeated values diff() of sorted vector will have no zeroes
--
char1 =
2a
3d
4c
1g
5h
8f
6e
7f
then u=unique(char(char1(:))) gave me:
u =
1
2
3
4
5
6
7
8
a
c
d
e
f
g
h
so just using find in u won't tell me whether or not there is more than one use of any of those characters in char1.
No, but sum() of find() would, albeit repetitively, which was the reason
I said this way needed further thought...
--
The key is to think about what are characteristics of the set you're
looking for. I think this should work well as long as the size of the
data set isn't too large so that sort() isn't a real bottleneck.
--
This has been bugging me--_KNEW_ had to be way to avoid the temporary... :)
Try
all(diff(sort(horzcat(c{:}))))
NOTA BENE: the {} instead of () to dereference the cell contents for
the concatenation operation.
--