How to merge two D arrays according a given order?

1 回表示 (過去 30 日間)
Aditya Shukla
Aditya Shukla 2015 年 6 月 16 日
編集済み: Aditya Shukla 2015 年 6 月 17 日
Hi all, I want to merge two D arrays according a given order.
Suppose I have two arrays id1=[ 3 5 6] and id2=[1 4 7] and coordinates of these ids id1_coords=[23 45;34 66;34 24] and [26 34;46 78; 34 67]
Now, if I sort and merge id1 and id2 as merge_id= union(id1,id2); merge_id=[1 3 4 5 6 7]; So how could i merge id1_coords and id2_coords such that they are arranged in the same sequence as it is in merge_id i.e.
merge_coords will be like..[26 34; 23 45;46 78.....] soon.
  1 件のコメント
Aditya Shukla
Aditya Shukla 2015 年 6 月 17 日
編集済み: Aditya Shukla 2015 年 6 月 17 日
Hi, Suppose if i get the array like this
m=
1 14 56
2 12 45
2 34 65
3 78 56
4 64 34
4 45 23
.......
but i want to delete rows having same ids{but different coordinates},
here-'2',and -'4' . i.e want to retain any one of the rows '2' and '4'.
somewhat like this..
m=
1 14 56
2 12 45
3 78 56
4 64 34
.......
It could be any id, [not only 2 and 4].

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

採用された回答

Mischa Kim
Mischa Kim 2015 年 6 月 16 日
Aditya, how about
ID1 = [id1' id1_coords];
ID2 = [id2' id2_coords];
ID = sortrows([ID1; ID2])
ID =
1 26 34
3 23 45
4 46 78
5 34 66
6 34 24
7 34 67
  1 件のコメント
Aditya Shukla
Aditya Shukla 2015 年 6 月 17 日
Thanks Kim for such an easy solution

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by