Taking unique numbers of a set and order them with their respective number

2 ビュー (過去 30 日間)
Ruben Alfaro
Ruben Alfaro 2014 年 4 月 18 日
回答済み: Ruben Alfaro 2014 年 4 月 18 日
Hello, I have a question i need hel with,
if i have this two vectors that go with each other
angle= [0; 1; 5; 3; 7; 8; 6; 9; 2; 4; 0]
radius= [ 2; 4; 6; 7; 8; 9; 6; 4; 3; 3; 2]
For example angle 0 goes with radius 2, angle 1 goes with radius 4 and so on... I want to take away the repeated angles and order them from smaller to bigger and keep their respective radius with them to get something like this
angle= [ 0; 1; 2; 3; 4; 5; 6; 7; 8; 9]
radius= [ 2; 4; 3; 7; 3; 6; 6; 8; 9; 4]
I really need help with this thank you very much

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 4 月 18 日
unique will be your friend:
angle= [0; 1; 5; 3; 7; 8; 6; 9; 2; 4; 0];
radius= [ 2; 4; 6; 7; 8; 9; 6; 4; 3; 3; 2];
% unique angles and index of first occurence
[uv,id,~] = unique(angle);
% extract
ang = uv
rad = radius(id)

その他の回答 (3 件)

Walter Roberson
Walter Roberson 2014 年 4 月 18 日
ar = unique([angle, radius], 'rows');
angle = ar(:,1);
radius = ar(:,2);

dpb
dpb 2014 年 4 月 18 日
>> unique([angle radius],'rows')
ans =
0 2
1 4
2 3
3 7
4 3
5 6
6 6
7 8
8 9
9 4
>>

Ruben Alfaro
Ruben Alfaro 2014 年 4 月 18 日
Thanks to all of you for your responses , they were very helpful.
you guys are awesome haha

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by