find duplicate values, sort them and get their indices
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Adam
il 15 Ago 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
0 Commenti
Più risposte (2)
Joakim Magnusson
il 15 Ago 2014
Modificato: Joakim Magnusson
il 15 Ago 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 Commenti
Joakim Magnusson
il 15 Ago 2014
Modificato: Joakim Magnusson
il 15 Ago 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];
Iain
il 15 Ago 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))
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!