Create a matrix with only the rows indexed by a multiple of N of another matrix.

조회 수: 1 (최근 30일)
Hello everyone!
And I am trying to create a matrix, containing only the rows indexed by (1+3x) of a given matrix. In other words, the first row and then jump every 3 rows until the end of the original matrix
Concretely, I have something that looks like this:
x1 = randi([0, 10], [9,2])
x1 =
5 10
4 6
4 5
2 1
1 1
4 8
9 8
3 5
6 6
And I am trying to get this:
x2 =
5 10
2 1
9 8
Is there any straightforward way to do this?
Thanks!

채택된 답변

David Hill
David Hill 2020년 5월 4일
x2=x1(1:3:length(x1),:);

추가 답변 (1개)

Prasad Reddy
Prasad Reddy 2020년 5월 4일
clc
clear all
x1=randi([0,10],[9,2])
x2=[]
for i=1:3:length(x1)
x2=[x2; x1(i,:)]
end
% this will work

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by