Count number 1 in the row

1 次查看(过去 30 天)
Dear all, I have this range:
x=[0 0 0 1 0 1 0 0]
I want to count number 1 in this row. Could you help me? Thanks.

采纳的回答

Quynh tran
Quynh tran 2017-5-11
Thanks everybody, I had my solution
count=sum(x)

更多回答(3 个)

Gennaro Arguzzi
Gennaro Arguzzi 2017-5-11
编辑:Gennaro Arguzzi 2017-5-11
z=[0 0 0 1 0 1 0 0];
a=length(z);
b=0;
for i=1:a
if(z(i)==1)
b=b+1;
end
end

KSSV
KSSV 2017-5-11
x=[0 0 0 1 0 1 0 0] ;
nnz(x)
find(x==1)
x(x==1)

Aamer Ejaz
Aamer Ejaz 2020-2-20
length(find(X)==1)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by