How to count?

조회 수: 2 (최근 30일)
Negar
Negar 2011년 4월 5일
Hello all, I have a stochastic signal, and I want to count how many of the samples are positive,and how many are negative. Any suggestions?
  댓글 수: 1
Negar
Negar 2011년 4월 5일
Here is my signal:
x1 = 2*(rand(1,N)>0.5)-1;
It is a binay stochastic signal with samples equal to either 1 or -1.
Thanks a lot..

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

채택된 답변

Robert Cumming
Robert Cumming 2011년 4월 5일
To find how many equal -1
answer = length(find ( x1 == -1 ));

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2011년 4월 5일
Hi Negar,
just count them
nPos = sum(x1==1)
nNeg = sum(x1==-1)
Titus
  댓글 수: 1
Jan
Jan 2011년 4월 5일
SUM is usually faster than LENGTH(FIND).
nNeg = numel(x1) - nPos

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

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by