This seems to work -
x = linspace(-10,5, 10)
start = -10;
stop = 5;
num_elements = 10;
index = 4;
out = start + (index-1)*(stop - start)./(num_elements-1)
Output -
x =
-10.0000 -8.3333 -6.6667 -5.0000 -3.3333 -1.6667 0 1.6667 ...
out =
-5
Thus, (stop - start)./(num_elements-1)
would be the stepsize
.
So, if you want the complete array, do this -
complete_array = start : (stop - start)./(num_elements-1) :stop
But, be careful of the floating point precision issues if you are comparing these results against the linspace
results - What is the advantage of linspace over the colon “:” operator?
.