Is there an equivalent to MATLAB's linspace? [duplicate]

Does Mathematica have an equivalent to Matlab's linspace? I want to make a list with "start", "stop" and "number of points". What is the neatest way of doing this?

-

marked as duplicate by rm -rf♦Dec 1 '13 at 17:21

There was an update for Array, not done to the end. The method below does not work for earlier versions even though that Array is

Moreover WRI forgot to update docs for error messages: Array::plen - the first example gives no error in V9.

V9

Array[# &, n, {start, stop}]

Array[# &, 10, {-1, 1}]

{-1, -(7/9), -(5/9), -(1/3), -(1/9), 1/9, 1/3, 5/9, 7/9, 1}


V<9

ClearAll[linespace];
linespace[s_, f_, 1] := (f + s)/2
linespace[s_, f_, n_] := Range[s, f, (f - s)/(n - 1)]


-
Nice, this one I´ll crib shamelessly :D –  Yves Klett Nov 29 '13 at 12:29
Is this new in v9? –  ssch Nov 29 '13 at 12:30
@ssch In v9, Array is said to be last modyfied in v4. Also I think I've seen this syntax in Mr.Wizard's answers so in that case it was working in v7. –  Kuba Nov 29 '13 at 12:31
I like Array, work like charm –  Vibhor Singh Nov 29 '13 at 12:45
@Kuba when I try this, or equivalent examples on the Documentation site, I get error 'Array::plen: "{10} and {-1,1} should have the same length'. Examples where the 2nd and 3rd values are Lists of equal length work fine (e.g 'Array[f, {2, 3}, {{-1/2, 1/2}, {0, 1}}]' ). Any thoughts ? –  PlaysDice Nov 29 '13 at 14:11
linspace[start_, stop_, n_:100] := Table[x, {x, start, stop, (stop - start)/(n - 1)}]

it is the way too, be careful with n=1. –  Kuba Nov 29 '13 at 18:21
it seems there is no good answer :) n=1 seems useless but on the other hand, why not? –  Kuba Nov 29 '13 at 19:02