The answer of Sam Roberts provides some additional information and clarifies further things, including some statements of MathWorks regarding the colon operator. In your special case, as you create a vector of integers, there is no advantage of linspace (apart from usability), but when it comes to floating point delicate tasks, there may is. linspace tries to ensure (as the name suggests) linear spacing, whereas colon tries to ensure symmetry To sum up: linspace and colon are reliable at doing different tasks. Using linspace can reduce the probability of occurance of these issues, it's not a security.Ĭ = (d2 - d1).*(n1-1) % opposite signs may cause overflow In my opinion it's a matter of how likely you will get floating point issues and how much you can reduce the probabilty for them or how small can you set the tolerances. You shouldn't rely on any of the computed values being exactly what you expect. But as Mark Dickinson pointed out in the comments: Which can be avoided by linspace, as a single division of an integer is not that delicate, like the cumulative sum of floting point numbers.
Well, it's basically a floating point issue. Imagine you need to define bin edges for a histogram. The : colon creates the vector directly by increments. It is the same, the main difference and advantage of linspace is that it generates a vector of integers with the desired length (or default 100) and scales it afterwards to the desired range. Similar to the colon operator :, but gives direct control over the The linspace function generates linearly spaced vectors.