From: crispin Donnelly on
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!
From: ImageAnalyst on
Not exactly sure what you're asking, but how about this:
dd = a;
That should do the trick.
From: crispin Donnelly on
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
From: Oleg Komarov on
"crispin Donnelly" <odonnellracing(a)gmail.com> wrote in message <hlh8pl$9bs$1(a)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
From: crispin Donnelly on
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!!