How to construct this matrix without using two for loops?

2 ビュー (過去 30 日間)
Mohit Kumar
Mohit Kumar 2021 年 5 月 13 日
回答済み: Mohit Kumar 2021 年 5 月 13 日
Hi, I'm trying to construct a matrix in the following manner:
sz=10;
V=rand(sz,sz);
X=rand(sz,sz);
for iter1=1:sz
for iter2=1:sz
A(iter1,iter2) = sum((V(:,iter1)*V(:,iter2)').*X,[1 2]);
end
end
Is there a way to do this without for-loops? I'm sure there must be a way that I haven't been able to think of!
  2 件のコメント
DGM
DGM 2021 年 5 月 13 日
編集済み: DGM 2021 年 5 月 13 日
What are i and j? By default, both i and j are sqrt(-1), which isn't a valid index. Are they supposed to be iter1 and iter2, or are they defined elsewhere and constant within the scope of the loops?
Mohit Kumar
Mohit Kumar 2021 年 5 月 13 日
My bad, i mean iter1 and iter2. Edited the question. Thanks.

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

回答 (1 件)

Mohit Kumar
Mohit Kumar 2021 年 5 月 13 日
I was able to figure out the answer to this. The formulation can be written as
A = V' * X * V;

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by