find duplicate values, sort them and get their indices

2 ビュー (過去 30 日間)
F Z
F Z 2014 年 8 月 15 日
コメント済み: F Z 2014 年 8 月 15 日
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

採用された回答

Adam
Adam 2014 年 8 月 15 日
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

その他の回答 (2 件)

Joakim Magnusson
Joakim Magnusson 2014 年 8 月 15 日
編集済み: Joakim Magnusson 2014 年 8 月 15 日
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 件のコメント
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 15 日
編集済み: Joakim Magnusson 2014 年 8 月 15 日
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 2014 年 8 月 15 日
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
Iain 2014 年 8 月 15 日
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 件のコメント
F Z
F Z 2014 年 8 月 15 日
Thank you all for your answers. I'll try to do it in a loop for each position

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by