# Am unable to wrap my head on this question regarding for loop , can someone explain the question and maybe write the code please.

1 visualizzazione (ultimi 30 giorni)
Dawud Adam Rabiu il 10 Nov 2021
Commentato: Awais Saeed il 10 Nov 2021
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Walter Roberson il 10 Nov 2021
A number of solutions have been posted already; search for halfsum

Accedi per commentare.

### Risposta accettata

Awais Saeed il 10 Nov 2021
Why use a loop if it can be done without it
A = [1 2 3; 4 5 6; 7 8 9];
[sum_of_elements] = halfsum(A)
sum_of_elements = 26
function [sum_of_elements] = halfsum(M)
A = M;
sum_of_elements = sum(triu(A), 'all');
end
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Dawud Adam Rabiu il 10 Nov 2021
Thank you Awais, can you explain the lines of code please ?
Awais Saeed il 10 Nov 2021

Accedi per commentare.

### Categorie

Scopri di più su Loops and Conditional Statements 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