Borrar filtros
Borrar filtros

how to swap this matrix

1 visualización (últimos 30 días)
Anusha
Anusha el 17 de Oct. de 2013
Editada: Andrei Bobrov el 17 de Oct. de 2013
i have this column of matrix
Z= 2
4
1
7
9
how to swap this 1 and 2

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 17 de Oct. de 2013
Editada: Andrei Bobrov el 17 de Oct. de 2013
Z([1,2]) = Z([2,1]);
ADD
Z = [2
4
2
1
7
9
1
1]; % new case
a = [1, 2]; % replacement value
[l,ii] = ismember(Z,a);
Z(l) = a(3-ii(l));
  2 comentarios
Anusha
Anusha el 17 de Oct. de 2013
how to swap 1st and 3rd position
Andrei Bobrov
Andrei Bobrov el 17 de Oct. de 2013
Z([1,3]) = Z([3,1]);

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 17 de Oct. de 2013
Z(1:3)=flipud(Z(1:3));
Only works because of odd number, of course. In general to swap individual elements will still take the temporary to hold the one element while overwrite the other.

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by