How to track elements in a matrix that switch their position when converting into another matrix?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Maryam S
le 30 Août 2019
Commenté : Maryam Sadeghi
le 30 Août 2019
Hi, Could you please help me find a solution to this problem:
Matrix A gives the index of a set of 2 particles (i;ii) distributed in 10 columns (2*10). Matrix B gives the index of these particles after 1 second and Matrix C gives their index after 2 seconds. For instance, if particle i is introduced at position 7 in matrix A, it would get to position 4 after t time; particle i from 4th column in matrix B would end in column 9 in Matrix C. I would like to track the trajectory of these particles as a function of time and their initial position (see Xi and Xii). For instance, the trajectory of particle i that is introduced at 7th is : from column 7 to column 4 and from 4 to 9 after 2 seconds.
A = [1 2 3 4 5 6 7 8 9 10;1 2 3 4 5 6 7 8 9 10]
B = [1 1 1 1 2 3 4 5 6 7;1 1 1 1 1 1 1 1 2 3]
C= [6 7 8 9 10 10 10 10 10 10;4 5 6 7 8 9 10 10 10 10]
Thanks in advance
Maryam
0 commentaires
Réponse acceptée
Stephen23
le 30 Août 2019
>> A = [1,2,3,4,5,6,7,8,9,10;1,2,3,4,5,6,7,8,9,10];
>> B = [1,1,1,1,2,3,4,5,6,7;1,1,1,1,1,1,1,1,2,3];
>> C = [6,7,8,9,10,10,10,10,10,10;4,5,6,7,8,9,10,10,10,10];
>> Xi = A([1,1,1],:); % preallocate
>> Xi(2,:) = B(1,Xi(1,:));
>> Xi(3,:) = C(1,Xi(2,:))
Xi =
1 2 3 4 5 6 7 8 9 10
1 1 1 1 2 3 4 5 6 7
6 6 6 6 7 8 9 10 10 10
>> Xii = A([2,2,2],:); % preallocate
>> Xii(2,:) = B(2,Xii(1,:));
>> Xii(3,:) = C(2,Xii(2,:))
Xii =
1 2 3 4 5 6 7 8 9 10
1 1 1 1 1 1 1 1 2 3
4 4 4 4 4 4 4 4 5 6
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB 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!