how to sum of column without sum function in a unit metrix

11 Ansichten (letzte 30 Tage)
MD Anower Hossain
MD Anower Hossain am 21 Sep. 2019
Kommentiert: Matt J am 21 Sep. 2019
x1 = [1 2 3; 4 5 6; 7 8 9];
all =(x1);
summa=0;
count = 0;
for i=1:length(all)
% fprintf("%d\n",i);
summa = 0;
for j = 1:length(all)
summa = summa + all(j);
% fprintf("%d ",j);
end
fprintf("%d ",summa);
end
I want to sum every column without sum function , i tried it but i can't can anyone help me please ?

Akzeptierte Antwort

Matt J
Matt J am 21 Sep. 2019
summa = summa + all(j,i);
  2 Kommentare
MD Anower Hossain
MD Anower Hossain am 21 Sep. 2019
can you please describe it why you use all(j,i); why j and i ? i used only j .
Matt J
Matt J am 21 Sep. 2019
Without this, "i" is not used anywhere. Why did you include a loop over "i" if you are not going to use it?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices 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!

Translated by