Getting off diagonals after calculating a correlation matrix

1 view (last 30 days)
The code below gives the first off diagonals of the correlation computation in line 6. How do I get the others?
testm1 = [1,2,3,4,5,6,7,8;2,4,5,7,10,6,7,8]; testm2 = [1,2,3,4,5,6,7,8;3,1,4,3,0,1,2,3]; num_pts = 8; testm1= transpose(testm1); testm2= transpose(testm2); corr = testm1(:,2)*testm2(:,2)' main_diag = testm1(:,2).*testm2(:,2) i = 1; diags1{i} = testm1(i:num_pts - i,2).*testm2(i+1:num_pts-i + 1,2); disp('off diagonal above') disp(diags1{i}) diags2{i} = testm2(i:num_pts - i,2).*testm1(i+1:num_pts-i + 1,2); disp('off diagonal below') disp(diags2{i})
corr = 6 2 8 6 0 2 4 6 12 4 16 12 0 4 8 12 15 5 20 15 0 5 10 15 21 7 28 21 0 7 14 21 30 10 40 30 0 10 20 30 18 6 24 18 0 6 12 18 21 7 28 21 0 7 14 21 24 8 32 24 0 8 16 24 main_diag = 6 4 20 21 0 6 14 24 off diagonal above 6 4 20 21 0 6 14 off diagonal below 12 5 28 30 0 7 16

Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!