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

1 回表示 (過去 30 日間)
Diego Hens
Diego Hens 2020 年 10 月 2 日
コメント済み: Diego Hens 2020 年 10 月 9 日
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

回答 (1 件)

Athul Prakash
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!
  1 件のコメント
Diego Hens
Diego Hens 2020 年 10 月 9 日
Hello Athul,
thanks for the answer. Could you elaborate a bit? I do not really understand what you propose.
Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by