Find the sum of the non perimeter elements of a matrix using a for loop
Afficher commentaires plus anciens
I have this matrix
B=[-3 4 7;9 11 -13;-17 19 -23;-29 31 37;39 41 47]
and I need to find the sum of the non perimeter elements using a for loop. I can find the sum of a single column or row or of the whole matrix, but I don't know how to write a loop to only sum the 3 non perimeter numbers. Any help is appreciated, thank you.
Réponse acceptée
Plus de réponses (2)
Azzi Abdelmalek
le 24 Avr 2016
Modifié(e) : Azzi Abdelmalek
le 24 Avr 2016
A=B
A(:,[1 end])=0
A([1 end],:)=0
out=sum(A(:))
Ibrahim Abouemira
le 19 Mai 2019
0 votes
Hello,
Here's a function that performs your required task.
Catégories
En savoir plus sur Aerospace Blockset 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!