Hi,
I have a array A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9] and want output B
= [1 2 4 7 8 9]
i.e. select only the unique numbers from the array and discard all
numbers that get repeated in the original array.
I have tried with 'unique' and then a for loop which 'find' number of
occurrence of a element of the output of unique in the original array.
I want to simplify this and try to remove the for loop.
gopla <gopalgajjar@gmail.com> wrote in message
<1193230486.076915.167300@z24g2000prh.googlegroups.com>...
> Hi,
> I have a array A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9] and want output B
> = [1 2 4 7 8 9]
>
> i.e. select only the unique numbers from the array and discard all
> numbers that get repeated in the original array.
>
> I have tried with 'unique' and then a for loop which 'find' number of
> occurrence of a element of the output of unique in the original array.
> I want to simplify this and try to remove the for loop.
A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9];
[B,count] = consolidator(A);
B(count>1) = [];
B =
1
2
4
7
8
9
Find consolidator on the file exchange. (Beware
the wrapped URL. Copy both lines into your
browser)
gopla <gopalgajjar@gmail.com> wrote in message
<1193230486.076915.167300@z24g2000prh.googlegroups.com>...
> Hi,
> I have a array A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9] and
want output B
> = [1 2 4 7 8 9]
>
> i.e. select only the unique numbers from the array and
discard all
> numbers that get repeated in the original array.
>
You may want to try histc.
> I have tried with 'unique' and then a for loop which
'find' number of
> occurrence of a element of the output of unique in the
original array.
> I want to simplify this and try to remove the for loop.
>
One possible way
A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9];
AA = unique(A);
n = histc(A,AA);
AA(n==1);
gopla <gopalgajjar@gmail.com> wrote in message
<1193230486.076915.167300@z24g2000prh.googlegroups.com>...
> Hi,
> I have a array A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9] and
want output B
> = [1 2 4 7 8 9]
>
> i.e. select only the unique numbers from the array and
discard all
> numbers that get repeated in the original array.
>
> I have tried with 'unique' and then a for loop which
'find' number of
> occurrence of a element of the output of unique in the
original array.
> I want to simplify this and try to remove the for loop.
>
> With Regards
> Gopla
>
Here's one approach that uses the tabulate function (see
help in statistics toolbox):
> I have a array A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9] and want output B
> = [1 2 4 7 8 9]
>
> i.e. select only the unique numbers from the array and discard all
> numbers that get repeated in the original array.
>
> I have tried with 'unique' and then a for loop which 'find' number of
> occurrence of a element of the output of unique in the original array.
> I want to simplify this and try to remove the for loop.
One possible way is using *union* (operation on sets).
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.