reducing number of operations in matrix multiplication

4 ビュー (過去 30 日間)
Douglas Brenner
Douglas Brenner 2018 年 10 月 10 日
回答済み: Douglas Brenner 2018 年 10 月 11 日
I want to perform the follow operation: synch = spect1(1:num_pts ,2)*spect2(1:num_pts,2)'; The problem is that num_pts > 300,000. Would take too long. Fortunately, I don't need the entire output. I only need the diagonal elements plus elements from the say 10 adjacent diagonals on either side. Anybody know how to do this or want to take a guess? Thanks

回答 (2 件)

Douglas Brenner
Douglas Brenner 2018 年 10 月 11 日
編集済み: Torsten 2018 年 10 月 11 日
testm = [1,2,3,4,5;2,4,5,7,10]
num_pts = 5;
testm = transpose(testm)
corr = testm(:,2)*testm(:,2)'
diag(corr)
main_diag = testm(:,2).*testm(:,2)
for i=1:3
diags1{i} = testm(i+1:num_pts ,2).*testm(1:num_pts-i-1,2);
diags2{i} = testm(i+1:num_pts ,2).*testm(1:num_pts-i-1,2);
end
failed at diags1{i} = testm(i+1:num_pts ,2).*testm(1:num_pts-i-1,2); Error using .* Matrix dimensions must agree. Error in test (line 8) diags1{i} = testm(i+1:num_pts ,2).*testm(1:num_pts-i-1,2);
Got to run.
  1 件のコメント
Torsten
Torsten 2018 年 10 月 11 日
The number of elements of testm(i+1:num_pts,2) and testm(1:num_pts-i-1,2) are not the same ...

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


Douglas Brenner
Douglas Brenner 2018 年 10 月 11 日
Clearly but that was the suggested solution. Trying for i=1:2 diags1{i} = testm(i+1:num_pts-i-1 ,2).*testm(1:num_pts-i-1,2); diags2{i} = testm(i+1:num_pts-i-1 ,2).*testm(1:num_pts-i-1,2); end
gives the same error as does other attempts to fix it

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by