Recurring Sequences of Numbers

10 visualizaciones (últimos 30 días)
C
C el 1 de Oct. de 2017
Comentada: Stephen23 el 1 de Oct. de 2017
Is there a way to declare v as a vector of numbers without a stopping point [0 -1 0 1 0 -1 0 1 ... n]? And from that I want to be able to use the number a to get all the entries of vector v. For example: a = 4 v = [0 -1 0 1]

Respuesta aceptada

Stephen23
Stephen23 el 1 de Oct. de 2017
>> fun = @(N)round(cos((1:N)*pi/2));
>> fun(10)
ans =
0 -1 0 1 0 -1 0 1 0 -1
>> fun(4)
ans =
0 -1 0 1
  2 comentarios
C
C el 1 de Oct. de 2017
What would the function look like to do the same for [0 1 0 -1 ... n]? I've tried using the fun function with sin instead of cos, but the first value is 1 instead of 0.
Stephen23
Stephen23 el 1 de Oct. de 2017
You need to also offset the range of input values, e.g.:
(0:N-1)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Elementary Math en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by