MATLAB: Sum across columns for each row

matrixmdcmsumstopsisvectors

I have a 296×6 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.

Best Answer

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