help please why ??

7 Ansichten (letzte 30 Tage)
ahmad qadan
ahmad qadan am 28 Feb. 2018
Kommentiert: ahmad qadan am 28 Feb. 2018
A = [ 1 3 2 6 ; 5 7 7 0 ; -2 6 -2 1 ] ;
j = sum(A(1))
j= 1 why ???

Akzeptierte Antwort

Jim Riggs
Jim Riggs am 28 Feb. 2018
the statement
sum(A(1))
is summing only the first element in A, which is 1.
If you want to sum the first row, it should be
sum(A(1,:))
and if you want to sum the first column, it is
sum (A(:,1))
  3 Kommentare
Jim Riggs
Jim Riggs am 28 Feb. 2018
The matrix A is:
1 3 2 6
5 7 7 0
-2 6 -2 1
The first element in A is A(1) which is 1. So the statement
sum(A(1))
is the same as
sum(1)
and has a value of 1.
ahmad qadan
ahmad qadan am 28 Feb. 2018
oooohhh ok thx a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

elham kreem
elham kreem am 28 Feb. 2018
WHAT are you want? IF YOU want to sum all the values then use Sum (A) BUt you sum the first element only. IF you help this answer then except to it.
  1 Kommentar
ahmad qadan
ahmad qadan am 28 Feb. 2018
why j = 1 ,, if the sum first element 1+1 = 2

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by