Take lines from array

조회 수: 17 (최근 30일)
j shen
j shen 2019년 1월 4일
편집: Stephan 2019년 1월 4일
I have an 64X4 array A , and I want take out every first 2 lines in every 4 line, is there some easy way to do that?

채택된 답변

Stephan
Stephan 2019년 1월 4일
편집: Stephan 2019년 1월 4일
A = repmat([1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4],16,1); % Example matrix
B = zeros(32,4); % Preallocate B
B(1:2:end) = A(1:4:end,:); % Take line 1 of every 4.th line in A
B(2:2:end) = A(2:4:end,:); % Take line 2 of every 4.th line in A
results in:
A =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
B =
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
1 1 1 1
2 2 2 2
  댓글 수: 1
j shen
j shen 2019년 1월 4일
Thank you!

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

추가 답변 (1개)

KSSV
KSSV 2019년 1월 4일
A = rand(64,2) ;
B = reshape(A',2,4,[]) ;
B = permute(B,[2 1 3]) ;
iwant = B(1:2,:,:) ;

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by