Multiply a column by -1, then do something. Do this for all possible combinations of the matrix

1 visualización (últimos 30 días)
Hello,
I have:
  • a matrix U1 and U2 (whose columns are eigenvectors of another matrices)
  • myfunction(U1,U2), which takes U1 and U2 and calculates a matrix Z from them. From Z I want to take the smallest number of each row.
I would like to:
  • calculate the new matrix of U1 and U2 that gives me the smallest numbers for Z (as a result of using myfunction(U)), by means of multiplying one or more columns of U by -1.
This is my last stand trying to save the possibility of using a method for a project. For some context (it's not necessary for the question, I think, but maybe someone saw the other one, who knows) you can read the question here. I post this in a different thread because there may be someone someday trying to do a similar thing. I've solved many of my problems with other people's questions.
The solution could be, for example, that U1(:,2), U2(:,2) and U2(:,4) should be multiplied by -1 for me to get the correct Z.
I hope I made my question clear, if not I apologize and would gladly answer your questions to clarify it.
As always, thank you :D

Respuestas (1)

Athul Prakash
Athul Prakash el 9 de Oct. de 2020
Hey Diego,
I think you can attempt this problem using logical indexing. It's often faster to group all the combinations into a single multidimensional array and use logical indexing to slice into that array.
You may generate all the 2^n combinations of +- signs in a single logical array.
Hope it helps!
  1 comentario
Diego Hens
Diego Hens el 9 de Oct. de 2020
Hello Athul,
thanks for the answer. Could you elaborate a bit? I do not really understand what you propose.
Thank you!

Iniciar sesión para comentar.

Categorías

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