Multiply a column by -1, then do something. Do this for all possible combinations of the matrix
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Athul Prakash
2020-10-9
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!