tags:

views:

62

answers:

1

So, I have a vector:

k = 1:100;

And I want to take 19 elements from it, which are roughly equally-spaced. So I write this:

m = k(1:(99/18):end);

This works great, except for a tiny problem:

Warning: Integer operands are required for colon operator when used as index

m =

     1     7    12    18    23    29    34    40    45    51    56    62    67    73    78    84    89    95   100

Now, I understand why this comes up, but I'd like to get rid of that warning. Is there a "right" way to do this without a warning?

+8  A: 

Try this:

floor(linspace(1,100,19))
Well, in real life, K isn't just a linear vector. However, I suppose `m = k(floor(linspace(1, numel(k), 19))` is pretty good.
rlbond

related questions