How to rearrange/reconstruct the matrix with the indeces?

1 回表示 (過去 30 日間)
Yonghyeon Jeon
Yonghyeon Jeon 2021 年 2 月 17 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 17 日
I have at sample matrix
A = [ 11, 12 ; 21, 22 ; 31, 32 ; 41, 42];
and index matrix
Idx = [ 2 2 ; 1 2 ; 3 4 ; 4 1];
I want to rearrange the matrix A to
RA = [ 12, 22 ; 11, 22 ; 13, 24 ; 14 , 21];
This result means that the first columnn of the matrix RA is rearrange of the first columnn of the matrix A by the first column of the index matrix Idx
and
the second columnn of the matrix RA is rearrange of the second columnn of the matrix A by the second column of the index matrix Idx

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 17 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 17 日
"This result means that the first columnn of the matrix RA is rearrange of the first columnn of the matrix A by the first column of the index matrix Idx";
and
"the second columnn of the matrix RA is rearrange of the second columnn of the matrix A by the second column of the index matrix Idx:
Doubt: I have doubt between text description and RA result, maybe I'm wrong?
A = [ 11, 12 ; 21, 22 ; 31, 32 ; 41, 42]
Idx = [ 2 2 ; 1 2 ; 3 4 ; 4 1]
my_RA=[A(Idx(:,1),1),A(Idx(:,2),2)]
your_RA= [ 12, 22 ; 11, 22 ; 13, 24 ; 14 , 21]
Result:
A =
11 12
21 22
31 32
41 42
Idx =
2 2
1 2
3 4
4 1
my_RA =
21 22
11 22
31 42
41 12
your_RA =
12 22
11 22
13 24
14 21

カテゴリ

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