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:
How to find to SAME entries in a matrix?

Subject: How to find to SAME entries in a matrix?

From: Talieh Z

Date: 14 Sep, 2010 15:55:36

Message: 1 of 2

Hi,

I am using a large matrix with a possibility of having same entries for two of the columns of interest. I'd appreciate if anyone could direct me on how to find these values without writing loops within loops, and only by using the provided functions on Matlab.

Example:
A = [ 123 456 0.4 0.3 0.5 0.3
         894 345 0.1 0.2 0.4 0.3
         234 921 0.9 0.4 0.3 0.2
         123 456 0.2 0.3 0.2 0.5
         921 234 0.3 0.8 0.3 0.5]

I want a piece of code to:
1- detect the same two entries for the first two rows:
answer: 1 and 4
row 1: [ 123 456 ]
row 4: [ 123 456 ]

2- detect the pair that is swapped:
answer: 3 and 5
row 3: [ 234 921 ]
row 5: [ 921 234 ]

Thanks,
Talieh

Subject: How to find to SAME entries in a matrix?

From: Sean

Date: 14 Sep, 2010 16:40:26

Message: 2 of 2

"Talieh Z" <t.zarabzadeh@gmail.com> wrote in message <i6o5to$664$1@fred.mathworks.com>...
> Hi,
>
> I am using a large matrix with a possibility of having same entries for two of the columns of interest. I'd appreciate if anyone could direct me on how to find these values without writing loops within loops, and only by using the provided functions on Matlab.
>
> Example:
> A = [ 123 456 0.4 0.3 0.5 0.3
> 894 345 0.1 0.2 0.4 0.3
> 234 921 0.9 0.4 0.3 0.2
> 123 456 0.2 0.3 0.2 0.5
> 921 234 0.3 0.8 0.3 0.5]
>
> I want a piece of code to:
> 1- detect the same two entries for the first two rows: (COLUMNS?)
> answer: 1 and 4
> row 1: [ 123 456 ]
> row 4: [ 123 456 ]
>
> 2- detect the pair that is swapped:
> answer: 3 and 5
> row 3: [ 234 921 ]
> row 5: [ 921 234 ]
>

A hint:
help unique;
help sort %with a special look at the second input argument

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