Borrar filtros
Borrar filtros

how to interchange array elements

3 visualizaciones (últimos 30 días)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 28 de Mzo. de 2013
my input is x=[11 12 13 14 15]. my output should be y=[15 12 13 14 11]. how to interchange particular values without disturbing other elements.?

Respuestas (2)

Andrei Bobrov
Andrei Bobrov el 28 de Mzo. de 2013
x = [11 12 13 14 15];
y = x;
y([end,1]) = y([1,end]);

Honglei Chen
Honglei Chen el 28 de Mzo. de 2013
Not sure if this is what you are looking for, but here is one way to do it, as long as you know the order
y = x([5 2 3 4 1])
  2 comentarios
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 28 de Mzo. de 2013
no. first element and last element should be interchanged is my objective..
Cedric
Cedric el 28 de Mzo. de 2013
y = [x(end), x(2:end-1), x(1)] ;

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by