how i count the values.

조회 수: 2 (최근 30일)
glory pachnanda
glory pachnanda 2013년 3월 20일
suppose, a=[1,2,3,4,5,6,7,8], the size of this matrix 1 rows and 8 columns and total values are 8, how can we count these total values on MATLAB. the result should be show like as 8 means if a has total values 1000 then the result should be 1000.

채택된 답변

Image Analyst
Image Analyst 2013년 3월 20일
What exactly do you mean by count? Do you mean the sum (total) of all elements, or the number of elements? Do you mean a count of the number of elements? Like
numberOfColumns = size(a, 2);
numberOfColumns = length(a);
numberOfColumns = numel(a);
All of the above will give numberOfColumns = 8 for an 8 element row vector, and numberOfColumns = 1000 for a 1000 element row vector.

추가 답변 (1개)

Jason Ross
Jason Ross 2013년 3월 20일
편집: Jason Ross 2013년 3월 20일
Are you just looking for the sum? In that case, use "sum"
>> a=[1,2,3,4,5,6,7,8]
a =
1 2 3 4 5 6 7 8
>> sum(a)
ans =
36

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by