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:
sorting matrices

Subject: sorting matrices

From: Peter Schreiber

Date: 24 Dec, 2008 00:08:25

Message: 1 of 5

Hi,
I have a matrix like:

A=[1 4 3 2;
     3 0 2 9;
     2 1 5 3;
     1 2 3 4;
     9 3 9 9;
...
]

and I would like to randomly flip rows. At least all rows have different entries.
Is there any short way of accomplishing this?

Best Regards,
Peter

Subject: sorting matrices

From: Roger Stafford

Date: 24 Dec, 2008 00:20:30

Message: 2 of 5

"Peter Schreiber" <schreiber.peter15@gmail.com> wrote in message <giruhp$but$1@fred.mathworks.com>...
> Hi,
> I have a matrix like:
>
> A=[1 4 3 2;
> 3 0 2 9;
> 2 1 5 3;
> 1 2 3 4;
> 9 3 9 9;
> ...
> ]
>
> and I would like to randomly flip rows. At least all rows have different entries.
> Is there any short way of accomplishing this?
>
> Best Regards,
> Peter

 A = A(randperm(size(A,1)),:)

Roger Stafford

Subject: sorting matrices

From: Roger Stafford

Date: 24 Dec, 2008 00:34:05

Message: 3 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <girv8d$otr$1@fred.mathworks.com>...
> "Peter Schreiber" <schreiber.peter15@gmail.com> wrote in message <giruhp$but$1@fred.mathworks.com>...
> > .... At least all rows have different entries.
>
> A = A(randperm(size(A,1)),:)

  I take back that solution. I didn't read your request carefully enough.

Roger Stafford

Subject: sorting matrices

From: Roger Stafford

Date: 24 Dec, 2008 03:27:04

Message: 4 of 5

"Peter Schreiber" <schreiber.peter15@gmail.com> wrote in message <giruhp$but$1@fred.mathworks.com>...
> Hi,
> I have a matrix like:
>
> A=[1 4 3 2;
> 3 0 2 9;
> 2 1 5 3;
> 1 2 3 4;
> 9 3 9 9;
> ...
> ]
>
> and I would like to randomly flip rows. At least all rows have different entries.
> Is there any short way of accomplishing this?
>
> Best Regards,
> Peter

  Peter, I am not certain of what you meant by the sentence, "At least all rows have different entries." For a time I thought you meant that the rearrangement had to be such that no row would be left in its original position. That is why I withdrew my original solution. Such a requirement would make a very interesting problem out of it.

  However on rereading the sentence I am not sure that was your meaning. Could you please elucidate this for us? What do you mean by a different entry? Do you mean that no two rows in the matrix are alike? And if so, what has this to do with random "flipping"?

Roger Stafford

Subject: sorting matrices

From: Peter Schreiber

Date: 24 Dec, 2008 04:02:29

Message: 5 of 5

Dear Mr. Stafford,
Sorry for the confusion. Your previous answer was the one I was looking for.
Thanks a lot merry X-mas,
Peter

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gisa68$60j$1@fred.mathworks.com>...
> "Peter Schreiber" <schreiber.peter15@gmail.com> wrote in message <giruhp$but$1@fred.mathworks.com>...
> > Hi,
> > I have a matrix like:
> >
> > A=[1 4 3 2;
> > 3 0 2 9;
> > 2 1 5 3;
> > 1 2 3 4;
> > 9 3 9 9;
> > ...
> > ]
> >
> > and I would like to randomly flip rows. At least all rows have different entries.
> > Is there any short way of accomplishing this?
> >
> > Best Regards,
> > Peter
>
> Peter, I am not certain of what you meant by the sentence, "At least all rows have different entries." For a time I thought you meant that the rearrangement had to be such that no row would be left in its original position. That is why I withdrew my original solution. Such a requirement would make a very interesting problem out of it.
>
> However on rereading the sentence I am not sure that was your meaning. Could you please elucidate this for us? What do you mean by a different entry? Do you mean that no two rows in the matrix are alike? And if so, what has this to do with random "flipping"?
>
> Roger Stafford

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