フィルターのクリア

Vectorise matrix element multiplication

1 回表示 (過去 30 日間)
Divij Gupta
Divij Gupta 2021 年 6 月 22 日
回答済み: KSSV 2021 年 6 月 22 日
I want to find a way to vectorise the following operation:
  • Take q random elements from the cell Z (which is populated by matrices)
  • Multiply them together into a matrix
Here is how I am doing it right now:
combo_matrix = nchoosek(1:N,q);
H = zeros(2^(N/2));
for i = 1:combo
rand_index = randi(size(combo_matrix,1));
h = eye(2^(N/2));
for c = 1:q
h = h*Z{combo_matrix(rand_index,c)};
end
H = H + h;
combo_matrix(rand_index,:) = [];
end
H = complex(0,1)^(q/2) * H;

回答 (1 件)

KSSV
KSSV 2021 年 6 月 22 日
If Z is a matrix. You can replace the loop:
for c = 1:q
h = h*Z{combo_matrix(rand_index,c)};
end
with
c = 1:q ;
h = prod(Z(combo_matrix(rand_index,c)))

カテゴリ

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