필터 지우기
필터 지우기

find duplicate values, sort them and get their indices

조회 수: 1 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by