I have to find the sum of the elements in the upper dimension matrix and this is the code i came up with. When I submitted this code it's showing error.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MANOGNA POTLURI
le 14 Juil 2020
Commenté : MANOGNA POTLURI
le 14 Juil 2020
function summa=halfsum(A)
n=length(A);
k=1;
[m,p]=size(A);
if m~=p
return
else
summa=0;
for i=1:n
for j=k:n
summa=summa+A(i,j);
end
k=k+1;
end
end
2 commentaires
Réponse acceptée
David Hill
le 14 Juil 2020
Why not just:
[a,b]=size(A);
if a==b
summa=sum(triu(A),'all');
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing 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!