Effacer les filtres
Effacer les filtres

How to rearrange/reconstruct the matrix with the indeces?

1 vue (au cours des 30 derniers jours)
Yonghyeon Jeon
Yonghyeon Jeon le 17 Fév 2021
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

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 17 Fév 2021
Modifié(e) : KALYAN ACHARJYA le 17 Fév 2021
"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

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by