Index of reordered vector

1 回表示 (過去 30 日間)
N Madani SYED
N Madani SYED 2012 年 3 月 30 日
Hi all
I better ask my question directly through example
Suppose A = [1 2 3 4 5 6] and I reorder the vector A to get AR = [ 2 4 1 6 5 3]. Now, I wish to track the position of elements of A in AR (i.e. I wish to get vector P = [3 1 6 2 5 4]) so that I can get original vector A by renumbering AR using P (i.e. AO = AR(P) so that A=AO); how can I get vector P?
Regards N Madani SYED

採用された回答

Matt Kindig
Matt Kindig 2012 年 3 月 30 日
A = [1 2 3 4 5 6]
AR = [2 4 1 6 5 3]
[junk, P] = ismember(A, AR)
  1 件のコメント
N Madani SYED
N Madani SYED 2012 年 3 月 30 日
Thanks.

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

その他の回答 (1 件)

Thomas
Thomas 2012 年 3 月 30 日
A = [1 2 3 4 5 6];
AR=[ 2 4 1 6 5 3];
[x,y,P]=intersect(A,AR)
x =
Columns 1 through 5
1.00 2.00 3.00 4.00 5.00
Column 6
6.00
y =
Columns 1 through 5
1.00 2.00 3.00 4.00 5.00
Column 6
6.00
P =
Columns 1 through 5
3.00 1.00 6.00 2.00 5.00
Column 6
4.00
You have the vector P as output of intersect
  1 件のコメント
N Madani SYED
N Madani SYED 2012 年 3 月 30 日
Thanks.

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

カテゴリ

Help Center および File ExchangeGPU Computing in MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by