Finding minimum of sum of columns
Afficher commentaires plus anciens
hello guys, thank you for all that you do here.
Please i need help on this code as i have been stuck on this for a while.
This is a simplified version of my code:
a = [2 9 2 8 9 0 1];
b = [3 1 6 2 9 2 5];
c = [0 4 8 7 4 8 3];
d = [a;b;c]
if d(1,1)==d(2,1)||d(1,1)==d(3,1)||d(2,1)==d(3,1) %if at least two of column 1 are the same
return row d that has the minimum sum of columns 4 to 7 (insert code here)
if at least two of the sums of columns 4 to 7 are the same (insert code here);
return row d that has the maximum sum of columns 2 to 3 (insert code here);
if at least two of the sums of columns 2 to 3 are the same (insert code here);
n = d(1,:); %return the first row of d (that is [2 9 2 8 9 0 1])
I would be glad to give more details where needed. Thank you
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 29 Juil 2017
[~, rowidx] =min( sum(d(:,4:7), 2) );
return_value = d(rowidx,:)
4 commentaires
Chiamaka Agwuegbo
le 30 Juil 2017
Walter Roberson
le 30 Juil 2017
2 is not the rowidx: 2 is the dimension number to sum along. Notice it is not inside the d() expression: it is at the level of the sum()
John BG
le 30 Juil 2017
sum(A)
and
sum(A,1)
are the same, dimension 1 being sum along vertical.
When aiming at horizontal summation dimension 2 has to be specified.
Chiamaka Agwuegbo
le 31 Juil 2017
Catégories
En savoir plus sur Multidimensional Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!