필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

rearrangement matrix rows based on vector of indicies

조회 수: 1 (최근 30일)
Abbi Hashem
Abbi Hashem 2020년 3월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
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
per isakson
per isakson 2020년 3월 2일
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

답변 (1개)

Matt J
Matt J 2020년 3월 2일
편집: Matt J 2020년 3월 2일
You want this,
clear Final_Coordinates
Final_Coordinates(I,:)=Coordinates;

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by