필터 지우기
필터 지우기

Sorting matrices in matlab

조회 수: 3 (최근 30일)
Matija Kosak
Matija Kosak 2018년 7월 5일
댓글: Matija Kosak 2018년 7월 5일
Hello,
I have a NxM matrix:
Random A for example 10x5
A =
2 8 7 1 4
9 8 8 1 7
4 8 2 8 8
3 3 2 10 6
8 7 6 7 8
1 6 5 2 3
1 4 9 8 8
7 1 8 2 10
7 8 8 2 9
6 4 1 7 1
I would like to make another matrix (B) that contains first every N, N+2, N+4...and after them N+1,N+3.. ect
B =
2 8 7 1 4
4 8 2 8 8
8 7 6 7 8
1 4 9 8 8
7 8 8 2 9
9 8 8 1 7
3 3 2 10 6
1 6 5 2 3
7 1 8 2 10
6 4 1 7 1
Thank you.
  댓글 수: 1
Stephen23
Stephen23 2018년 7월 5일
Note that this is a topic of indexing/rearranging the elements, where the element values are not relevant to the new order (only their indices are). Sorting depends only on the element values (not their indices).

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 7월 5일
>> B = A([1:2:end,2:2:end],:)
B =
2 8 7 1 4
4 8 2 8 8
8 7 6 7 8
1 4 9 8 8
7 8 8 2 9
9 8 8 1 7
3 3 2 10 6
1 6 5 2 3
7 1 8 2 10
6 4 1 7 1
  댓글 수: 4
Matija Kosak
Matija Kosak 2018년 7월 5일
That's not good for what I need because it mix numbers. I would need for numbers in rows to be same.
Matija Kosak
Matija Kosak 2018년 7월 5일
It works now, thank you a lot :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by