Select only determined rows in a matrix

조회 수: 2 (최근 30일)
Emilio Pulli
Emilio Pulli 2021년 11월 28일
댓글: Emilio Pulli 2021년 11월 28일
I have a matrix composed of 200 rows and I want to copy in another matrix one every 10 rows obtaining a final matrix of 20 rows...is there a smart way to do it or do I have to use a for loop to index the orws I want to copy?

채택된 답변

the cyclist
the cyclist 2021년 11월 28일
% First matrix
A = rand(200,2);
% New matrix
B = A(10:10:end,:); % This will start with the 10th row. You could do B = A(1:10:end,:) to start with the first row.

추가 답변 (1개)

DGM
DGM 2021년 11월 28일
Something like this. You'll have to adjust the starting index as needed:
A = repmat((1:100).',[1 4]) % smaller example (100x4)
A = 100×4
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10
B = A(10:10:end,:)
B = 10×4
10 10 10 10 20 20 20 20 30 30 30 30 40 40 40 40 50 50 50 50 60 60 60 60 70 70 70 70 80 80 80 80 90 90 90 90 100 100 100 100

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by