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:
Matrix trick

Subject: Matrix trick

From: David Edson

Date: 14 Apr, 2010 21:07:03

Message: 1 of 6

Hello,
I need help. If I have a matrix B, how would I get C, which is a matrix with out repeatition of elements in B, Which function should I call?


 B=[ 313 549
   604 154
   154 604
   549 604];

C= B=[ 313 549
   604 154 ];

thanks

Subject: Matrix trick

From: Rune Allnor

Date: 14 Apr, 2010 21:11:43

Message: 2 of 6

On 14 apr, 23:07, "David Edson" <toja...@example.com> wrote:
> Hello,
> I need help. If I have a matrix B, how would I get C, which is a matrix with out repeatition of elements in B, Which function should I call?
>
>  B=[ 313   549
>    604   154
>    154   604
>    549   604];
>
> C= B=[ 313   549
>    604   154  ];
>
> thanks

doc colon
doc unique

Rune

Subject: Matrix trick

From: David Edson

Date: 14 Apr, 2010 21:22:04

Message: 3 of 6



Hi Rune,

Unique function does not help. I do not want to see an element be repeated in either rows.

Subject: Matrix trick

From: Jan Simon

Date: 14 Apr, 2010 21:30:21

Message: 4 of 6

Dear David!

> B=[ 313 549
> 604 154
> 154 604
> 549 604];
>
> C= B=[ 313 549
> 604 154 ];

As Rune I'd suggest unique.
But you do not tell us, how the resulting matrix is exactly defined!
unique(B(:)) gives the elements, but there seems to be a further idea behind your C.

Jan

Subject: Matrix trick

From: Bruno Luong

Date: 14 Apr, 2010 21:37:04

Message: 5 of 6

"David Edson"
>
> I do not want to see an element be repeated in either rows.

Stupid question: How do you want to output be for

A = [1 2;
    2 3;
   3 1]

?

Bruno

Subject: Matrix trick

From: dpb

Date: 14 Apr, 2010 22:26:05

Message: 6 of 6

Jan Simon wrote:
> Dear David!
>
>> B=[ 313 549
>> 604 154
>> 154 604
>> 549 604];
>>
>> C= B=[ 313 549
>> 604 154 ];
>
> As Rune I'd suggest unique.
> But you do not tell us, how the resulting matrix is exactly defined!
> unique(B(:)) gives the elements, but there seems to be a further idea
> behind your C.

Indeed, whether it was happenstance or carefully contrived, it happens
to have the four unique elements in the first two rows of a two-column
matrix and all the remaining elements as duplicates of those values.

In general, unless there is a very unique (so to speak :) ) generating
mechanism, there needs to be some other rules applied.

Or, of course, if the above condition does hold in general, one might as
well terminate the generation process after the first two rows are
created and avoid the problem in the first place... :)

--

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