reducing number of operations in matrix multiplication

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by