Fast sampling every other element in a matrix

I have a matrix M. I want to delete every other column and every other row. However, I already know how to do this as:
M = rand(100,11);
M2=M;
M2(:,2:2:end)=[];
M2(2:2:end,:)=[];
I will have to do this operation on large matrices many times in a loop, thus I am wondering if matlab has a built-in function to do this faster. Thanks.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 10월 2일

2 개 추천

M2 = M(1:2:end,1:2:end);

댓글 수: 3

Much faster, thanks
Orongo
Orongo 2019년 2월 15일
what does the parameter 'end' mean here?
Stephen23
Stephen23 2019년 2월 15일
@Orongo: "The end function also serves as the last index in an indexing expression"

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2014년 10월 2일

댓글:

2019년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by