How to rearrange/reconstruct the matrix with the indeces?

1 次查看(过去 30 天)
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 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