How to a make an array of set length that spans a set of values.

i am trying to have a matrix with teh start point of -pi/2 and ends on pi/2 over a length of 65 points. so that the next value would be -pi/2+pi/2*1/64 with the final value being pi/2 at the end of the arrray or matrix. i think i can preallocate the matrix to be zeros and make it 65 untis long. then set the first value of the matrix to be -pi/2. then increase the interval or the point specified in the matrix and then just add the previous value in the matrix plus pi/2*1/64. i am trying to figure out if there is an easier way.

 Réponse acceptée

There is a much easier way, which is to use the function linspace:
x = linspace(-pi/2, pi/2, 65)
x = 1×65
-1.5708 -1.5217 -1.4726 -1.4235 -1.3744 -1.3254 -1.2763 -1.2272 -1.1781 -1.1290 -1.0799 -1.0308 -0.9817 -0.9327 -0.8836 -0.8345 -0.7854 -0.7363 -0.6872 -0.6381 -0.5890 -0.5400 -0.4909 -0.4418 -0.3927 -0.3436 -0.2945 -0.2454 -0.1963 -0.1473

Plus de réponses (0)

Catégories

Produits

Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by