how can i find the sum of matrix elements
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
if i have a two dimension matrix i want to create a for loop to compute the summation of element in this matrix like : sum= 0 for i=1 to n for j= 1 to m sum= sum + a[j,j] but in matlab!!!
0 commentaires
Réponses (2)
Star Strider
le 16 Avr 2014
Modifié(e) : Star Strider
le 16 Avr 2014
If you want to sum the diagonal elements of a, I suggest:
a = rand(5,5);
sd = sum(diag(a));
Do not use sum as a variable name. It is a built-in MATLAB function, and using it as a variable name will cause problems later in your code.
If you want the sum of all the elements in your matrix, I suggest:
sa = sum(a(:));
0 commentaires
Voir également
Catégories
En savoir plus sur Sparse Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!