Sum across columns for each row

조회 수: 1 (최근 30일)
Emma Kuttler
Emma Kuttler 2019년 11월 18일
댓글: Emma Kuttler 2019년 11월 18일
I have a 296x6 matrix called impactScore, and the maximum value (max1, max2 . . . max6) from each column(call them col1,col2 . . . col6).
For Row 1, i want to find
(row 1 col 2) - max1)^2
(row 1 col 2 - max2)^2
Repeat this for all 6 columns and sum this value
Repear this calculation for each row
Essentially
D pic.png
where i represents each row and j represents each column.

채택된 답변

Bhaskar R
Bhaskar R 2019년 11월 18일
Assuming yor question as
" (row 1 col 1) - max1)^2
(row 1 col 2 - max2)^2
(row 1 col 3) - max3)^2
(row 1 col 4) - max4)^2
(row 1 col 5) - max5)^2
(row 1 col 6 - max6)^2 "
Correct me if i am wrong
max_vals = max(impactScore); % maximum values of each colum(1 to 6)
D = zeros(size(impactScore,1), 1); % initialize
for ii =1: size(impactScore, 1)
D(ii, :) = sqrt(sum([impactScore(ii,:)-max_val].^2));
end
D % column matrix after calculation
  댓글 수: 1
Emma Kuttler
Emma Kuttler 2019년 11월 18일
It worked, just had to change max_val in line 4 to max_vals . Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by