find duplicate values, sort them and get their indices

2 views (last 30 days)
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].
Any solution to this please? Thank you in advance for your help

Accepted Answer

Adam
Adam on 15 Aug 2014
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

More Answers (2)

Joakim Magnusson
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]?
  3 Comments
Joakim Magnusson
Joakim Magnusson on 15 Aug 2014
Edited: Joakim Magnusson on 15 Aug 2014
do you mean like this?
ampPos15 = sort(Amplitude(tempV));
Will give this i think:
ampPos15 = [0 0.0100 0.0200 0.0600 0.1000 0.1500 0.2000 0.2500 0.2500 0.7000];
F Z
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?!!

Sign in to comment.


Iain
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))
  1 Comment
F Z
F Z on 15 Aug 2014
Thank you all for your answers. I'll try to do it in a loop for each position

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!