help please why ??

조회 수: 4 (최근 30일)
ahmad qadan
ahmad qadan 2018년 2월 28일
댓글: ahmad qadan 2018년 2월 28일
A = [ 1 3 2 6 ; 5 7 7 0 ; -2 6 -2 1 ] ;
j = sum(A(1))
j= 1 why ???

채택된 답변

Jim Riggs
Jim Riggs 2018년 2월 28일
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
Jim Riggs
Jim Riggs 2018년 2월 28일
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 2018년 2월 28일
oooohhh ok thx a lot

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

elham kreem
elham kreem 2018년 2월 28일
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
ahmad qadan
ahmad qadan 2018년 2월 28일
why j = 1 ,, if the sum first element 1+1 = 2

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by