Sum across columns for each row

1 visualizzazione (ultimi 30 giorni)
Emma Kuttler
Emma Kuttler il 18 Nov 2019
Commentato: Emma Kuttler il 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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by