Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
rearrangement matrix rows based on vector of indicies
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
I think I must be missing something simple here because I tried this before and it worked well, but not sure why it won't work in this case 
Here's what I have: 
a matrix that is 50*3 , named coordinates: 
1	1	1 
1	2	1
1	3	1
1	4	1
1	5	1
2	1	1
2	2	1
2	3	1
2	4	1
2	5	1
1	1	2
1	2	2
1	3	2
1	4	2
1	5	2
3	1	1
3	2	1
3	3	1
3	4	1
3	5	1
2	1	2
2	2	2
2	3	2
2	4	2
2	5	2
4	1	1
4	2	1
4	3	1
4	4	1
4	5	1
3	1	2
3	2	2
3	3	2
3	4	2
3	5	2
5	1	1
5	2	1
5	3	1
5	4	1
5	5	1
4	1	2
4	2	2
4	3	2
4	4	2
4	5	2
5	1	2
5	2	2
5	3	2
5	4	2
5	5	2
another matrix that is 50*1 named I (stands for Index) 
41	42	43	44	45	46	47	48	49	50	36	37	38	39	40	31	32	33	34	35	11	12	13	14	15	16	17	18	19	20	1	2	3	4	5	6	7	8	9	10	21	22	23	24	25	26	27	28	29	30
I want to re-arrange the "coordinates" matrix so that the 41st row contains  (1,1,1) , the 42nd row is the 2nd row(1 2 1) .... the 30th row contains 5,5,2. 
I type in the following: : Final_Coordinates=Coordinates(I,:); ..... But then I get the following( which is NOT what I want) 
4	1	2
4	2	2
4	3	2
4	4	2
4	5	2
5	1	2
5	2	2
5	3	2
5	4	2
5	5	2
5	1	1
5	2	1
5	3	1
5	4	1
5	5	1
3	1	2
3	2	2
3	3	2
3	4	2
3	5	2
1	1	2
1	2	2
1	3	2
1	4	2
1	5	2
3	1	1
3	2	1
3	3	1
3	4	1
3	5	1
1	1	1
1	2	1
1	3	1
1	4	1
1	5	1
2	1	1
2	2	1
2	3	1
2	4	1
2	5	1
2	1	2
2	2	2
2	3	2
2	4	2
2	5	2
4	1	1
4	2	1
4	3	1
4	4	1
4	5	1
( for some reason, the order is NOT according to the index)
Not sure what I'm doing wrong. Any help is appreciated ! 
1 Kommentar
  per isakson
      
      
 am 2 Mär. 2020
				I think Final_Coordinates is the result that should be expected. So, what do you want?
It is easier to debug code with small examples of data. Make a Minimal working example
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


