How to create a for loop to do sums of every values in the whole row?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Darkhan Kenestegi
am 15 Dez. 2016
Kommentiert: Darkhan Kenestegi
am 15 Dez. 2016
I have a matrix lets say a=[1,2,3;9,8,7;4,5,6]
I want to create a loop that will sum each row, like:
sum(a(1,:));
The problem is I want it to be repeated for every row.
Will appreciate any help! Cheers!
0 Kommentare
Akzeptierte Antwort
KSSV
am 15 Dez. 2016
a=[1,2,3;9,8,7;4,5,6] ;
b = zeros(size(a,2),1) ;
for i = 1:size(a,2)
b(i) = sum(a(i,:)) ;
end
b
b1 = sum(a,2)
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!