Is there some advantage of writing
t = linspace(0,20,21)
over
t = 0:1:20
?
I understand the fo
linspace
is useful where you know the number of elements you want rather than the size of the "step" between them. So if I said make a vector with 360 elements between 0
and 2*pi
as a contrived example it's either going to be
linspace(0, 2*pi, 360)
or if you just had the colon operator you would have to manually calculate the step size:
0:(2*pi - 0)/(360-1):2*pi
linspace
is just more convenient
For a simple real world application, see this answer where linspace
is helpful in creating a custom colour map