Borrar filtros
Borrar filtros

x = j:i:k creates a regularly-spaced vector x using i as the increment between elements. What about x = j:i:k:m? or j:i:k:m:n?

1 visualización (últimos 30 días)
I hope I am clear enough. I think it is very odd that this works with how many elements you want to separate with colons. It appears to disregard any elements in between the first and last.
This doesn't appear in the documentation.

Respuesta aceptada

James Tursa
James Tursa el 23 de Feb. de 2018
Editada: James Tursa el 23 de Feb. de 2018
This is simply left-to-right operator evaluation.
j:i:k:m:n
evaluates as
(j:i:k):m:n
And, as stated in the doc:
"If you specify nonscalar arrays, then MATLAB interprets j:i:k as j(1):i(1):k(1)."
So your syntax, although probably confusing, is covered in the doc and simply uses the first element of the created vectors at each intermediate result when generating the next intermediate result.
EDITED to delete comments that didn't apply
  2 comentarios
Guilherme Silva
Guilherme Silva el 23 de Feb. de 2018
I think it actually does evaluate as
(j:i:k):m:n
e.g.
1:2:3:4:5
ans =
1 5
(1:2:3):4:5
ans =
1 5
So it gets the first two colons, evaluates them and then uses the first element of the generated vector for the next two colons evaluation? It gets really confusing. Thanks for your answer.
James Tursa
James Tursa el 23 de Feb. de 2018
Editada: James Tursa el 23 de Feb. de 2018
You're right. I was using 1:2:3:4 as one of the test cases for my spot testing, but that doesn't match your five element pattern so that part of my answer didn't apply. I have edited my answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by