Sum across columns for each row

1 Ansicht (letzte 30 Tage)
Emma Kuttler
Emma Kuttler am 18 Nov. 2019
Kommentiert: Emma Kuttler am 18 Nov. 2019
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.

Akzeptierte Antwort

Bhaskar R
Bhaskar R am 18 Nov. 2019
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 Kommentar
Emma Kuttler
Emma Kuttler am 18 Nov. 2019
It worked, just had to change max_val in line 4 to max_vals . Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by