フィルターのクリア

Avoiding for loops for multiplication of multidimensional matrices

1 回表示 (過去 30 日間)
Tworit Dash
Tworit Dash 2022 年 6 月 1 日
コメント済み: Tworit Dash 2022 年 6 月 1 日
I have to do a matrix multiplication of two vectors in principle to get a scalar. The vectors are (1 x 2) and (2 x 1). However, I need to do this for a lot of cases. Those cases are defined in matrix form like the following.
for i = 1:Niter
for k = 1:Cn
for ti = 1:T
E(i, k, ti) = [D(ti, :) - squeeze(y(i, k, ti, :)).'] * [D(ti, :) - squeeze(y(i, k, ti, :)).'].'
end
end
end
So, `D` is a matrix with T x 2 size, y is a 4D matrix with size `Niter x Cn x T x 2`. Is there a way to avoid these for loops? I just want to compute the row and column vectors for all different cases `Niter`, `Cn` and `T`.

採用された回答

Matt J
Matt J 2022 年 6 月 1 日
編集済み: Matt J 2022 年 6 月 1 日
D=reshape(D,1,1,T,2);
E=vecnorm(D-y,2,4).^2;
  3 件のコメント
Matt J
Matt J 2022 年 6 月 1 日
The 3rd argument to vecnomr should have been 4, correct.
Tworit Dash
Tworit Dash 2022 年 6 月 1 日
Sorry yes, I meant the 3rd argument.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by