-1

I have to make an array that has 21 numbers from 0-5

They are supposed to be bins for a distribution

I am assuming what is being asked for is an array that has 21 numbers of equally spaced numbers

so the edges are

|0 to 0.2381|0.2381 to 0.4762|... and so on

How can I do this efficiently in matlab?

I can do this with a for loop, but is there a better way?

Kevin
  • 3,077
  • 6
  • 31
  • 77

1 Answers1

1

Yes, linspace does that for you.

>> linspace(0,5,22) % 22 because 0,5 are included

You can also use the : operator with the desired spacing:

>> 0:(5/21):5 % Create an array from 0 to 5 with spacing of 5/21
Some Guy
  • 1,787
  • 11
  • 15
  • Your second option is [**not recommend for creating bins**](http://stackoverflow.com/questions/26292695/what-is-the-advantage-of-linspace-over-the-colon-operator/26292912#26292912). – Robert Seifert Sep 08 '16 at 05:37