Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sorting displacements - help sought

1 view
Skip to first unread message

crispin Donnelly

unread,
Feb 17, 2010, 11:25:24 AM2/17/10
to
Hi! - A problem...

I have a vector, a = [10 20 50 60 90 30 40 70 80]
I have indexed and sorted the vector as follows;
[aa,bb]=sort(a)
Giving me the following
aa = 10 20 30 40 50 60 70 80 90
bb = 1 2 6 7 3 4 8 9 5

I would now like to quantify the displacement of each value, as follows:

cc = [1 2 3 4 5 6 7 8 9]
dd=cc-bb

giving:

dd = 0 0 -3 -3 2 2 -1 -1 4

after dd=dd.*-1

dd = 0 0 3 3 -2 -2 1 1 -4 (These values indicate how far and in what direction the original values of (a) have been moved in generating (aa).

Now the last step is the hard one I need help with.
How do I rearrange the values of (dd) back to their original position they occupied in (a)?

Any assistance greatly appreciated!

ImageAnalyst

unread,
Feb 17, 2010, 11:34:08 AM2/17/10
to
Not exactly sure what you're asking, but how about this:
dd = a;
That should do the trick.

crispin Donnelly

unread,
Feb 17, 2010, 12:25:09 PM2/17/10
to
Thanks but if you dont have anything constructive to say as you dont understand what I said then please leave the responses to those who do.
Thanks

Oleg Komarov

unread,
Feb 17, 2010, 12:42:09 PM2/17/10
to
"crispin Donnelly" <odonnel...@gmail.com> wrote in message <hlh8pl$9bs$1...@fred.mathworks.com>...

> Thanks but if you dont have anything constructive to say as you dont understand what I said then please leave the responses to those who do.
> Thanks
is this what you're trying to do:
dd(bb)
ans =
0 0 -2 1 3 3 1 -4 -2

Oleg

crispin Donnelly

unread,
Feb 17, 2010, 3:44:23 PM2/17/10
to
Thanks Oleg, but unfortunately not...

Each value in (dd) represents the magnitude and direction of displacement of a corresponding value of (a).
These values however correspond to the values of (a) after sorting. I need to rearrange (dd) so that the values correspond to the values of (a) before sorting.

Thanks in advance for any help.
If it helps make things clearer, the application of this problems is as follows;

I have a matrix (39x599) of seawater density values, within which there are instabilities (denser water lying above less dense water and vice versa). I need to quantify how far each water parcel needs to be displaced in order to make the water column stable (density increasing with depth).
If someone can answer my original problem I can apply the solution to my density profile.

Thanks once again in advance!!

Oleg Komarov

unread,
Feb 17, 2010, 3:59:08 PM2/17/10
to
"crispin Donnelly" <odonnel...@gmail.com> wrote in message <hlhkf7$kke$1...@fred.mathworks.com>...

See the other posts on the FEX. There are already several answers.
Oleg

Joshua Arnott

unread,
May 10, 2010, 12:26:22 PM5/10/10
to
"crispin Donnelly" <odonnel...@gmail.com> wrote in message <hlh59k$ka7$1...@fred.mathworks.com>...

Just come across this task, and got stuck at exactly the same point.

L(thorpeIdx) = (1:length(thorpeIdx))'-thorpeIdx;

Or in your notation,

L(bb) = (1:length(bb))-bb;

J.

0 new messages