Sum across columns for each row

1 次查看(过去 30 天)
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