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!