NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
Pladio
Posts: 46
0 Kudos
Accepted Solution

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

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:smileyhappy: 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.

 

Trusted Enthusiast
aeastet
Posts: 2,198

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

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

 

Example.png

Tim
Johnson Controls
Holland Michigan
Member
Pladio
Posts: 46
0 Kudos

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

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.

Trusted Enthusiast
aeastet
Posts: 2,198
0 Kudos

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

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
Johnson Controls
Holland Michigan
Knight of NI
altenbach
Posts: 22,866
0 Kudos

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

[ Edited ]

 


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?


LabVIEW Champion . Oh, by the way, I work for peanutsKudos .

Member
VGA_CD-ROM
Posts: 159

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

[ Edited ]

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

Regards,
Vijay S.
National Instruments
Member
Pladio
Posts: 46
0 Kudos

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

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. 

 

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page