Tuesday, January 29, 2008

count how many Inf's are in a vector

the following command returns how many Inf's are in a vector

length(find(myVector==Inf))

2 comments:

Anonymous said...

Actually a faster way is this:
sum(isinf(myVector))

Anonymous said...

ah. yes. you are right. this is more elegant. but the long way may be easier to adapt to other requirements. for example, if you whant to count how many "2"s are in a row, or how many zeros.

thanks for the comment!

leg