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

1 view (last 30 days)
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

Answers (1)

Athul Prakash
Athul Prakash on 9 Oct 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!

Community Treasure Hunt

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

Start Hunting!