Multiply each column of a matrix by another matrix

9 ビュー (過去 30 日間)
Miguel Morgado
Miguel Morgado 2019 年 4 月 9 日
コメント済み: Miguel Morgado 2019 年 4 月 10 日
Hi,
I have 2 matrices, E of dimension 4x57 and J of dimension 4x4.
I'm trying to do the operation C = sqrt(E'*J*E) for each column of E, so that C ends up being a vector of length 57.
Any ideas of how to do this without a loop?
Thank you very much
  1 件のコメント
Adam
Adam 2019 年 4 月 9 日
E'*J*E
will result in a 57x57 matrix so what is the operation you are actually trying to achieve in ordder to get a length 57 vector?

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

採用された回答

James Tursa
James Tursa 2019 年 4 月 9 日
編集済み: James Tursa 2019 年 4 月 9 日
Another way:
C = sqrt(sum(E.*(J*E)));
For the sizes involved, you probably won't see any significant timing differences between this method and Johathan's method. For much larger sizes, this method does less overall calculations than Jonathan's method and may run faster as a result.
  1 件のコメント
Miguel Morgado
Miguel Morgado 2019 年 4 月 10 日
Worked perfectly, thank you very much

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

その他の回答 (1 件)

Jon
Jon 2019 年 4 月 9 日
If I understand your question correctly then the result of the "operation for each column of E" will be on the main diagonal of E'*J*E so you should get what you want using C = sqrt(diag(E'*J*E))

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by