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.

 Accepted Answer

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

3 Comments

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

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!