Borrar filtros
Borrar filtros

"plus/minus" sign operator

9 visualizaciones (últimos 30 días)
frwmetric
frwmetric el 17 de Mayo de 2013
Hi
I have a row matrix which is like n=[x,y,z] I need to consider plus and minus signs at the same time and get a permutations of them. In conclusion I need that solutions
n=[x,y,z]
n=[-x,y,z]
n=[x,-y,z]
n=[x,y,-z]
n=[-x,-y,z]
n=[-x,y,-z]
n=[x,-y,-z]
n=[-x,-y,-z]

Respuesta aceptada

Iain
Iain el 17 de Mayo de 2013
It depends what you want to do with it.
M = [1 1 1; 1 1 -1; 1 -1 1; 1 -1 -1; -1 1 1; -1 1 -1; -1 -1 1; -1 -1 -1];
Out = (M * Row')' ;
Each row of Out is what you want.
You might want to programatically generate M if you have more columns on your row.
  2 comentarios
Iman Ansari
Iman Ansari el 17 de Mayo de 2013
[a b c]=meshgrid([-1 1]);
M=[a(:) b(:) c(:)];
frwmetric
frwmetric el 17 de Mayo de 2013
thank you...

Iniciar sesión para comentar.

Más respuestas (1)

C.J. Harris
C.J. Harris el 17 de Mayo de 2013
Not exactly elegant, but it works:
A = [1 2 3];
B = (dec2bin(0:2^length(A)-1) - '0');
C = sum(B .* repmat(A, 2^length(A), 1), length(A)) + sum(~B .* repmat(-A, 2^length(A), 1), length(A));

Categorías

Más información sobre Equations 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