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 commentaire

Negar
Negar le 5 Avr 2011
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..

Connectez-vous pour commenter.

 Réponse acceptée

Robert Cumming
Robert Cumming le 5 Avr 2011

1 vote

To find how many equal -1
answer = length(find ( x1 == -1 ));

Plus de réponses (1)

Titus Edelhofer
Titus Edelhofer le 5 Avr 2011

2 votes

Hi Negar,
just count them
nPos = sum(x1==1)
nNeg = sum(x1==-1)
Titus

1 commentaire

Jan
Jan le 5 Avr 2011
SUM is usually faster than LENGTH(FIND).
nNeg = numel(x1) - nPos

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by