Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab noninteger step indexing

Tags:

matlab

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?

like image 721
rlbond Avatar asked May 17 '26 04:05

rlbond


1 Answers

Try this:

floor(linspace(1,100,19))
like image 106
dkantowitz Avatar answered May 19 '26 03:05

dkantowitz