Evenly distribute range of specified values within a vector

Posted by nofunsally on Stack Overflow See other posts from Stack Overflow or by nofunsally
Published on 2012-10-28T16:22:14Z Indexed on 2012/10/28 17:00 UTC
Read the original article Hit count: 122

Filed under:
|
|

I have a vector A and I want to populate it with values as evenly as possible. For example, if A is 1x30 and I want to use three values I would use a code like this below:

% A = zeros(1,30);
A([1:10])=0;
A([11:20])=1;
A([21:30])=2;

This works, but seems a bit cumbersome to me. Is there a more elegant way to evenly (as possible) distribute a specified range of values within a vector? I am intent on keeping each of the values in "clumps."

Thank you kindly in advance.

© Stack Overflow or respective owner

Related posts about matlab

Related posts about vector