Thread Subject: Sort and revert

Subject: Sort and revert

From: fas

Date: 13 Nov, 2008 05:53:54

Message: 1 of 7

Hi,
I have a vector which I have sorted B=sort(A); Now after changing the
10 values on either end I would like to take the vector back to A.
B=sort(A);
B(1:10)=20;
B(90:100)=70;
Now I want to transform B->A so that the indexing is same of what my A
was.

Since its an image I have to revert back to same indexing of vector
only with changed values that I did after sorting.

Any idea ?

Subject: Sort and revert

From: Ning

Date: 13 Nov, 2008 06:33:02

Message: 2 of 7

fas <faisalmufti@gmail.com> wrote in message <195e56e8-c7b9-49b3-839f-fd0468067e86@35g2000pry.googlegroups.com>...
> Hi,
> I have a vector which I have sorted B=sort(A); Now after changing the
> 10 values on either end I would like to take the vector back to A.
> B=sort(A);
> B(1:10)=20;
> B(90:100)=70;
> Now I want to transform B->A so that the indexing is same of what my A
> was.
>
> Since its an image I have to revert back to same indexing of vector
> only with changed values that I did after sorting.
>
> Any idea ?
That's easy. Try help sub2ind first, after you sorted and changed the vector, try help ind2sub.
May it helps.

Subject: Sort and revert

From: fas

Date: 13 Nov, 2008 06:46:35

Message: 3 of 7

On Nov 13, 5:33=A0pm, "Ning" <ning.ro...@gmail.com> wrote:
> fas <faisalmu...@gmail.com> wrote in message <195e56e8-c7b9-49b3-839f-fd0=
468067...@35g2000pry.googlegroups.com>...
> > Hi,
> > I have a vector which I have sorted B=3Dsort(A); Now after changing the
> > 10 values on either end I would like to take the vector back to A.
> > B=3Dsort(A);
> > B(1:10)=3D20;
> > B(90:100)=3D70;
> > Now I want to transform B->A so that the indexing is same of what my A
> > was.
>
> > Since its an image I have to revert back to same indexing of vector
> > only with changed values that I did after sorting.
>
> > Any idea ?
>
> That's easy. Try help sub2ind first, after you sorted and changed the vec=
tor, try help ind2sub.
> May it helps.

Sorry I could not work sub2ind for my case :(

Subject: Sort and revert

From: fas

Date: 13 Nov, 2008 06:48:49

Message: 4 of 7

On Nov 13, 5:33=A0pm, "Ning" <ning.ro...@gmail.com> wrote:
> fas <faisalmu...@gmail.com> wrote in message <195e56e8-c7b9-49b3-839f-fd0=
468067...@35g2000pry.googlegroups.com>...
> > Hi,
> > I have a vector which I have sorted B=3Dsort(A); Now after changing the
> > 10 values on either end I would like to take the vector back to A.
> > B=3Dsort(A);
> > B(1:10)=3D20;
> > B(90:100)=3D70;
> > Now I want to transform B->A so that the indexing is same of what my A
> > was.
>
> > Since its an image I have to revert back to same indexing of vector
> > only with changed values that I did after sorting.
>
> > Any idea ?
>
> That's easy. Try help sub2ind first, after you sorted and changed the vec=
tor, try help ind2sub.
> May it helps.

My data is already a vector.

Subject: Sort and revert

From: Roger Stafford

Date: 13 Nov, 2008 07:06:09

Message: 5 of 7

fas <faisalmufti@gmail.com> wrote in message <195e56e8-c7b9-49b3-839f-fd0468067e86@35g2000pry.googlegroups.com>...
> Hi,
> I have a vector which I have sorted B=sort(A); Now after changing the
> 10 values on either end I would like to take the vector back to A.
> B=sort(A);
> B(1:10)=20;
> B(90:100)=70;
> Now I want to transform B->A so that the indexing is same of what my A
> was.
>
> Since its an image I have to revert back to same indexing of vector
> only with changed values that I did after sorting.
>
> Any idea ?

  Use the second output argument of 'sort':

 [B,p] = sort(A);
 B(1:10) = 20;
 B(90:100) = 70;
 A(p) = B;

Roger Stafford

Subject: Sort and revert

From: Roger Stafford

Date: 13 Nov, 2008 13:15:03

Message: 6 of 7

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gfgjl1$r0c$1@fred.mathworks.com>...
> fas <faisalmufti@gmail.com> wrote in message <195e56e8-c7b9-49b3-839f-fd0468067e86@35g2000pry.googlegroups.com>...
> > Hi,
> > I have a vector which I have sorted B=sort(A); Now after changing the
> > 10 values on either end I would like to take the vector back to A.
> > B=sort(A);
> > B(1:10)=20;
> > B(90:100)=70;
> > Now I want to transform B->A so that the indexing is same of what my A
> > was.
> >
> > Since its an image I have to revert back to same indexing of vector
> > only with changed values that I did after sorting.
> >
> > Any idea ?
>
> Use the second output argument of 'sort':
>
> [B,p] = sort(A);
> B(1:10) = 20;
> B(90:100) = 70;
> A(p) = B;
>
> Roger Stafford

  Or you could do this instead:

 [p,p] = sort(A);
 A(p(1:10)) = 20;
 A(p(90:100)) = 70;

Roger Stafford

Subject: Sort and revert

From: fas

Date: 16 Nov, 2008 01:39:24

Message: 7 of 7

On Nov 14, 12:15=A0am, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Roger Stafford" <ellieandrogerxy...@mindspring.com.invalid> wrote in mes=
sage <gfgjl1$r0...@fred.mathworks.com>...
> > fas <faisalmu...@gmail.com> wrote in message <195e56e8-c7b9-49b3-839f-f=
d0468067...@35g2000pry.googlegroups.com>...
> > > Hi,
> > > I have a vector which I have sorted B=3Dsort(A); Now after changing t=
he
> > > 10 values on either end I would like to take the vector back to A.
> > > B=3Dsort(A);
> > > B(1:10)=3D20;
> > > B(90:100)=3D70;
> > > Now I want to transform B->A so that the indexing is same of what my =
A
> > > was.
>
> > > Since its an image I have to revert back to same indexing of vector
> > > only with changed values that I did after sorting.
>
> > > Any idea ?
>
> > =A0 Use the second output argument of 'sort':
>
> > =A0[B,p] =3D sort(A);
> > =A0B(1:10) =3D 20;
> > =A0B(90:100) =3D 70;
> > =A0A(p) =3D B;
>
> > Roger Stafford
>
> =A0 Or you could do this instead:
>
> =A0[p,p] =3D sort(A);
> =A0A(p(1:10)) =3D 20;
> =A0A(p(90:100)) =3D 70;
>
> Roger Stafford

Thanks a lot Roger!

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

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.

Contact us at files@mathworks.com