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!
Oleg
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!!
See the other posts on the FEX. There are already several answers.
Oleg
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.