How to track elements in a matrix that switch their position when converting into another matrix?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maryam S
am 30 Aug. 2019
Kommentiert: Maryam Sadeghi
am 30 Aug. 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 Kommentare
Akzeptierte Antwort
Stephen23
am 30 Aug. 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
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!