Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
no_repeated_digits_in_row

Subject: no_repeated_digits_in_row

From: Kate

Date: 30 Aug, 2010 06:41:06

Message: 1 of 8

Hi guys,

requesting some help again...........

I have matrix =

A = [ 10 10 4 ;
        3 2 1 ;
        67 5 5;
        45 38 9
        1 6 3]

I want the output such that it 'filters' rows where there are NO repeated digits within that row.

So my ideal answer would be:

Answer = [ 3 2 1;
                45 38 9
                 1 6 3]

Any help welcome....

Kate

Subject: no_repeated_digits_in_row

From: Oleg Komarov

Date: 30 Aug, 2010 07:18:03

Message: 2 of 8

"Kate " <chino_tones@hotmail.com> wrote in message <i5fjq1$spb$1@fred.mathworks.com>...
> Hi guys,
>
> requesting some help again...........
>
> I have matrix =
>
> A = [ 10 10 4 ;
> 3 2 1 ;
> 67 5 5;
> 45 38 9
> 1 6 3]
>
> I want the output such that it 'filters' rows where there are NO repeated digits within that row.
>
> So my ideal answer would be:
>
> Answer = [ 3 2 1;
> 45 38 9
> 1 6 3]
>
> Any help welcome....
>
> Kate

% Counts
freq = histc(A, unique(A),2);
% Select rows with no repetitions
A = A(~any(freq == 2,2),:)
A =
     3 2 1
    45 38 9
     1 6 3

Oleg

Subject: no_repeated_digits_in_row

From: Kate

Date: 30 Aug, 2010 07:35:05

Message: 3 of 8

Oleg,,
How can I make this more robust?

Such as for the following matrix:

A=[ 3 2 3 3 2
     3 2 3 3 3
     3 3 1 1 1
     3 3 1 1 2
     3 3 1 1 3
     3 3 1 2 1
     3 3 1 2 2
     3 3 1 2 3
     1 2 3 4 5]

where ideal answer I would like to get is:

Ideal_Answer =[ 1 2 3 4 5 ]

With your code , I got , which as we can see is NOT ideal since rows with repeated values still exist:

Incorrect_answer = [3 2 3 3 3
                              3 3 1 2 3
                              1 2 3 4 5 ]


thanks for the help.

kate

Subject: no_repeated_digits_in_row

From: Carl

Date: 30 Aug, 2010 07:58:04

Message: 4 of 8

"Kate " <chino_tones@hotmail.com> wrote in message <i5fmv9$ku7$1@fred.mathworks.com>...
> Oleg,,
> How can I make this more robust?
>
> Such as for the following matrix:
>
> A=[ 3 2 3 3 2
> 3 2 3 3 3
> 3 3 1 1 1
> 3 3 1 1 2
> 3 3 1 1 3
> 3 3 1 2 1
> 3 3 1 2 2
> 3 3 1 2 3
> 1 2 3 4 5]
>
> where ideal answer I would like to get is:
>
> Ideal_Answer =[ 1 2 3 4 5 ]
>
> With your code , I got , which as we can see is NOT ideal since rows with repeated values still exist:
>
> Incorrect_answer = [3 2 3 3 3
> 3 3 1 2 3
> 1 2 3 4 5 ]
>
>
> thanks for the help.
>
> kate

Have a look at the freq function (help freq), the code oleg provided and the solution it is giving. That should enable you to determine why the solution is incorrect and how to correct it.

Subject: no_repeated_digits_in_row

From: Oleg Komarov

Date: 30 Aug, 2010 08:24:07

Message: 5 of 8

"Kate " <chino_tones@hotmail.com> wrote in message <i5fmv9$ku7$1@fred.mathworks.com>...
> Oleg,,
> How can I make this more robust?
>
> Such as for the following matrix:
>
> A=[ 3 2 3 3 2
> 3 2 3 3 3
> 3 3 1 1 1
> 3 3 1 1 2
> 3 3 1 1 3
> 3 3 1 2 1
> 3 3 1 2 2
> 3 3 1 2 3
> 1 2 3 4 5]
>
> where ideal answer I would like to get is:
>
> Ideal_Answer =[ 1 2 3 4 5 ]
>
> With your code , I got , which as we can see is NOT ideal since rows with repeated values still exist:
>
> Incorrect_answer = [3 2 3 3 3
> 3 3 1 2 3
> 1 2 3 4 5 ]
>
>
> thanks for the help.
>
> kate

Change:
A = A(~any(freq == 2,2),:)
to:
A = A(~any(freq >= 2,2),:)

Oleg

Subject: no_repeated_digits_in_row

From: Walter Roberson

Date: 30 Aug, 2010 14:51:42

Message: 6 of 8

On 30/08/10 1:41 AM, Kate wrote:

> I have matrix =
> A = [ 10 10 4 ;
> 3 2 1 ;
> 67 5 5;
> 45 38 9
> 1 6 3]
>
> I want the output such that it 'filters' rows where there are NO
> repeated digits within that row.

In your examples (here and in your follow-ups), each row that you
filtered out had two entries with the same numeric value. In the
examples you gave, each row that you filtered out also had two values
that happened to contain the same decimal digits (e.g. the '1' of the
first '10' is the same as the '1' of the second '10'). Your examples
thus do not make it clear whether you want to work at the level of
numeric value or the level of decimal digits.

Either way, we should also inquire as to whether the entries you are
working with are _certain_ to be integers (e.g., they are of integer
data type or you have round() or fix() or floor() or ceil() them). If
they are not certain to be exact integers, then there is the possibility
that two entries might display the same but be different values in the
low level bits, and you should be considering whether entry-wise value
comparison should have a tolerance; likewise if your values are not
certain to be exact integers and you are working on the basis of decimal
digits, then you need to be aware that when converted in to its _full_
decimal expansion, a value that is not exactly an integer is often 55
digits or so (which would be certain to have repeated digits internally.)

Subject: no_repeated_digits_in_row

From: Roger Stafford

Date: 30 Aug, 2010 16:41:20

Message: 7 of 8

"Kate " <chino_tones@hotmail.com> wrote in message <i5fjq1$spb$1@fred.mathworks.com>...
> Hi guys,
>
> requesting some help again...........
>
> I have matrix =
>
> A = [ 10 10 4 ;
> 3 2 1 ;
> 67 5 5;
> 45 38 9
> 1 6 3]
>
> I want the output such that it 'filters' rows where there are NO repeated digits within that row.
>
> So my ideal answer would be:
>
> Answer = [ 3 2 1;
> 45 38 9
> 1 6 3]
>
> Any help welcome....
>
> Kate
- - - - - - - -
Answer = A(all(diff(sort(A,2),1,2),2),:);

Roger Stafford

Subject: no_repeated_digits_in_row

From: Kate

Date: 17 Oct, 2010 19:46:04

Message: 8 of 8

yet again...thanks roger

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us