LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create an array in if/else or case structure without 0's ?

Solved!
Go to solution

Hello,

 

I've been trying to do this for a while now.

I only managed to think of this in three ways:

1. (What I'm doing right now:) Create the array by going through a for loop, which populates the array by auto indexing. It populates with correct number if true and with a '0' if false. The idea was to delete the 0's later on in the code. This however seems highly ineffective.

 

2. Make use of a shift register, which automatically adds the correct number to an array. The problem is that the array will keep growing and growing and at the very least would tremendously slow down my program. At worst, it would crash.

 

So, my question is: How do I create an array that if a comparison is true, it puts the element in and if not it does nothing ?

 

I've attached a PNG snippet of my code.

 

Kind Regards,

 

David.

 

0 Kudos
Message 1 of 7
(6,537 Views)

I think that it need to look more like this to do what you want it to do.

 

Example.png

Tim
GHSP
Message 2 of 7
(6,528 Views)

Hi, 

 

Thanks for the quick reply, but what are you doing in the False case ? Just leave default if unwired ?

 

Also, will this not do what I said regarding having an ever enlarging array ? Which would take more time ?

 

Thanks,

 

David.

0 Kudos
Message 3 of 7
(6,520 Views)

Yes but I am not sure what you are actually tring to do. I do not have your code so I am not sure what you were doing in the false case so I just made it default. If you need an array of output over time you will have to keep building an array or try to build a buffer so you can rotate the data in the buffer. It shouldn't bee to hard to do that. I am not sure if that would work for what you are trying to do.

Tim
GHSP
0 Kudos
Message 4 of 7
(6,512 Views)

 


@Pladio wrote:

I've been trying to do this for a while now.


You did not explain what "this" is. Can you give some typical inputs and expected outputs? Populate your controls and indicators with typical data and make it the default efore attaching.

 


@Pladio wrote:

So, my question is: How do I create an array that if a comparison is true, it puts the element in and if not it does nothing ?


Your code show three different comparisons. Which one are you talking about.


Pladio wrote:

I've attached a PNG snippet of my code.

 

 


That code makes very little sense. Why is there a shift register if the data in it never changes? What is the purpose of the inner FOR loop? Why are you creating a 2D array?

 

Do you want to remove all rows where the corersponding SD is zero, for example?

0 Kudos
Message 5 of 7
(6,504 Views)
Solution
Accepted by topic author Pladio

If you want to only allocate exactly as much memory as you need for the array, you can count the number of True items in the boolean array first, and then allocate one of exactly that size. That way you are more memory- and time-efficient than either overallocating (such as, allocating an I32 array as large as the entire boolean array) or underallocating (starting with zero elements and letting it auto-grow each time you need to add on).

 

Count the True values, allocate an array only that large, and then replace each value in that new array with the index/"i' value where the True exists. Here's a VI snippet:

 

 exactAllocation.png

Message 6 of 7
(6,490 Views)

Sorry, the idea of me being vague is that it would require a two page essay to explain the entire code. This is just a subVI of a small loop in my my main code.

 

In brief:

The inputs are hard to populate manually since there are many possibilities. The input is a 2D-array of doubles, which basically holds analog signals for at least 4 channels, which capture data from a multi-electrode array. I then get a standard deviation, which gets multiplied by a multiplier. If the total is negative then the comparison checks if the signal at each sample of each signal is below that value. If the total is positive then the comparison checks if the signal is greater than the SD nultiplied by its multiplier. 

 

I then want to find out at which place in the array of samples, I get the true values. 

 

0 Kudos
Message 7 of 7
(6,456 Views)