# find duplicate values, sort them and get their indices

15 views (last 30 days)
F Z on 15 Aug 2014
Commented: F Z on 15 Aug 2014
Suppose i have 3 arrays:
Position=[ 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 17 18 18 18...]
Ray=[1 2 3 1 1 1 2 2 2 3 1 2 4 4 4 4 2 2 4 5 5...]
and Amplitude=[0.1 0.2 0.15 0.02 0.25 0.06 0 0.01 0.7 0.25 0.315 0 0.45 0.2 0.1 0.1 0.8 ...]
How can i get the rays corresponding to the position==15 (Here:
Ray(Position==15)=[1 2 3 1 1 1 2 2 2 3]), sort them in order to get Ray'(Position==15)= [1 1 1 1 2 2 2 2 3 3] and then extract the corresponding amplitudes [0.1 0.02 0.25 0.06 0.2 0 0.01 0.7 0.15 0.25].

rayPos15 = Ray( Position == 15 );
ampPos15 = Amplitude( Position == 15 );
[sortedRayPos15, idx] = sort( rayPos15 );
sortedAmpPos15 = ampPos15( idx );
There's probably a neater way to do it, but something like that should give the result you want I think

Joakim Magnusson on 15 Aug 2014
Edited: Joakim Magnusson on 15 Aug 2014
It's hard to understand what you mean, but here's my guess. if you do this:
tempV = Position==15;
tempV = sort(Ray(tempV));
Then tempV will look like this:
tempV = [1 1 1 1 2 2 2 2 3 3];
Is that of any help?
I couldn't understand how or why you want to get amplitudes [0.1 0.02 0.25 0.06 0.2 0 0.01 0.7 0.15 0.25]?
F Z on 15 Aug 2014
In fact, what i want to do is to get the amplitudes corresponding to the sorted TempV= [[1 1 1 1 2 2 2 2 3 3] that are [0.1 0.02 0.25 0.06 0.2 0 0.01 0.7 0.15 0.25]
Then sum the amplitudes corresponding to each ray: TempV==1, TempV==2 ..etc
Hope that it's getting clearer?!!

Iain on 15 Aug 2014
This might be what you're looking for:
Amplitude(Position == 15 & Ray == 1)
Ot maybe:
RayNumbers = Ray(Position == 15);
URayNumbers = unique(RayNumbers);
URayNumbers(1)
Amplitude(Position == 15 & Ray == URayNumbers(1))
F Z on 15 Aug 2014
Thank you all for your answers. I'll try to do it in a loop for each position