How to select a fixed number of rows with constant spacing?

Hello,
I am sure there is an easy fix for my problem but I just can't figure out.
I am trying to extract 21 rows out of matrices. The spacing between the 21 rows should be constant for a given matrix with the first and last selected rows being the first and last rows of the matrix. I have tried to use the following code:
sel = mat(1:floor(size(mat,1)/20):size(mat,1),:);
but the problem is that as mat changes size, I do not always obtain 21 rows in sel.
Would someone have a solution for me?
Thank you,
Benoit

 Accepted Answer

A=rand(210,10); % example
A(fix(linspace(1,size(A,1),21)),:)

More Answers (1)

Benoit
Benoit on 18 Jun 2013
Edited: Benoit on 18 Jun 2013
That is awesome. Thank you Azzi Abdelmalek

Categories

Find more on Interactions, Camera Views, and Lighting in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!