04-16-2014 10:52 AM
How to find the number of 1s or 0s from a boolean array. e.g. in 101011, there are four 1s and two 0s.
Solved! Go to Solution.
04-16-2014 02:33 PM
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.
04-17-2014 01:41 AM
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.
04-17-2014 04:47 AM
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
04-17-2014 04:49 AM
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
04-17-2014 05:38 AM
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"?
04-17-2014 06:45 AM
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
04-17-2014 06:49 AM - edited 04-17-2014 06:51 AM
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.
04-17-2014 06:55 AM
Hi,
Thank you all.
I have just got an idea and its working. Its better i should share with you.
Thanks.
04-17-2014 07:34 AM
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!