LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of 1s or 0s from a boolean array

Solved!
Go to solution

How to find the number of 1s or 0s from a boolean array. e.g. in 101011, there are four 1s and two 0s.

0 Kudos
Message 1 of 11
(5,929 Views)

Hello ABBPAK,

 

This sounds like an asignment, so let me give you an idea: you start from the beginning of the array and compare each element with the value you want to count (0 or 1). If you find the value that you're looking for at the current index, you increment your counter and increment the index. When you reach to the end of the array, you're done. The value of the counter is the number of 1s or 0s.

How does that sound?

 

Best regards,

= Nelu F. || National Instruments.

0 Kudos
Message 2 of 11
(5,923 Views)

Just a guess: CVI does not have a "native" boolean type.

May this question relate to LabVIEW? If so, you should post it to the appropriate board.

 

Having said this, another way to perform the task (easier in LV than in CVI) is to sort the array and simply count items until the first value change.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 11
(5,908 Views)

The solution is not so attractive. I wanted to do this by suing some simple digital logic instead of loop as there are already many loops in the project.

thanks

0 Kudos
Message 4 of 11
(5,898 Views)

Hi,

When you talk about the value change, how to predefine the first value and the last value. e.g. 1100011. here just twice a time value changes but there are four 1s and three 0s.

thanks

0 Kudos
Message 5 of 11
(5,897 Views)

ABBPAK ha scritto:

Hi,

When you talk about the value change, how to predefine the first value and the last value. e.g. 1100011. here just twice a time value changes but there are four 1s and three 0s.

thanks


Did you focus on the word "sort"? Smiley Wink



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 11
(5,891 Views)

Hi,

Not at all.

I am processing some biomedical signals. I have different channels configurations e.g. 5,6,12,...... The decision is based on the number of voltages available on each channel. If voltage is present on more than half of the channels thats indicate ok.

From each channels, I am getting one boolean value (TRUE/FALSE) and building in an array. Based on that array I have to decide. I think its more clear.

Thanks

0 Kudos
Message 7 of 11
(5,885 Views)

Hello ABBPAK

 

Maybe if, instead of building an array, you increment a counter when you find TRUE / FALSE, you will know how many boolean values are TRUE / FALSE. Basically, when you read the value from the channel, you know if you have to increment the counter or not. In the beginning of the scanning operation, you reset the counter to zero.

Does that make sense?

 

Best regards,

= Nelu F. || National Instruments.

0 Kudos
Message 8 of 11
(5,883 Views)
Solution
Accepted by topic author ABBPAK

Hi,

Thank you all.

I have just got an idea and its working. Its better i should share with you.

  1. Convert the boolean array into 0 ,1 (available in labiew boolean)
  2.  Just sum those 0, 1 using arithmetic sum
  3. Comapre the sum with the half of the number of the channels.
  4. if sum is greater or equal, its ok

Thanks.

 

0 Kudos
Message 9 of 11
(5,878 Views)

That's good and simple, provided you do not need to know which channel has a '1' or not.

And confirms that you are working in labVIEW! Smiley Wink



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 11
(5,872 Views)