Count number 1 in the row

1 Ansicht (letzte 30 Tage)
Quynh tran
Quynh tran am 11 Mai 2017
Kommentiert: madhan ravi am 20 Feb. 2020
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.

Akzeptierte Antwort

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

Weitere Antworten (3)

Gennaro Arguzzi
Gennaro Arguzzi am 11 Mai 2017
Bearbeitet: Gennaro Arguzzi am 11 Mai 2017
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 am 11 Mai 2017
x=[0 0 0 1 0 1 0 0] ;
nnz(x)
find(x==1)
x(x==1)

Aamer Ejaz
Aamer Ejaz am 20 Feb. 2020
length(find(X)==1)

Kategorien

Mehr zu Programming 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