10-20-2010 08:04 PM
I have been trying to find the easiest way to stop the output of values that are zero. I know there must be a an easy way, but I can't figure it out, maybe because I have never used labview before. Any help would be appreciated: see the attached.
The issue is with the primenumberlist. It outputs zeros and I'm trying to stop the output. I have included the other program so you can run the subroutine and see what I mean.
10-20-2010 09:57 PM - edited 10-20-2010 09:58 PM
Why are you creating a 2-D array to write data to a spreadsheet file when it seems like your end result is to just be a list which would be 1-dimensional?
Inside your For Loop, put a case structure. If the value is prime, then you can use build array to put the value at the end of the 1-D array. If it is not prime, then you just pass the 1-D array through.
On your For Loop, you initialize an empty 1-D array, and use a shift register to maintain its value from iteration to iteration. Now the only values that are put into the 1-D array are primes, and zeroes do not get built into the array.
10-20-2010 10:19 PM
Thank you. I think I finally understand the function of the shift register. It's basically a "dummy" variable that allows the loop to go through and not terminate without doing anything to the loop.
One more thing, the output right now changed into a row format. How do I change it into a column? I tried used the transpose array feature, but that's only for 2D. Is there something that will transpose the 1D array?
10-20-2010 10:31 PM
@Excelsius wrote:
Thank you. I think I finally understand the function of the shift register. It's basically a "dummy" variable that allows the loop to go through and not terminate without doing anything to the loop.
One more thing, the output right now changed into a row format. How do I change it into a column? I tried used the transpose array feature, but that's only for 2D. Is there something that will transpose the 1D array?
The shift register is sort of like a "dummy variable". It would be like a statement x=x+1 in a loop in a text based language where the variable X stores a value between loop iterations just like a shift register stores a value in a wire between loop iterations. I don't quite understand or agree with you 2nd part about "not terminate without doing anything to the loop."
If you aren't familiar with shift registers, then make sure you take the LabVIEW tutorials.
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
There are a few different ways to do the columns vs. rows on your data. But I think the easiest would be to build your 1-D array into a 2-D after the For Loop and before putting into the 2-D array input of the Write to Spreadsheet File. You'll have to experiment to see whether you need to connect a True or False constant to the Transpose Array? input of the Write to SS File VI.
10-20-2010 11:06 PM
Could you please elaborate on the conversion? I looked here: http://forums.ni.com/t5/LabVIEW/1d-array-into-2d-array/td-p/832823 but still did not see how to convert a 1D into 2D array.
10-20-2010 11:10 PM - edited 10-20-2010 11:10 PM
The same way you were doing in your original VI where you were building a scalar into a 1-D array.
You just use a Build array function with one input (the 1-D array) which then builds it into a the single output (which then becomes the 2-D array.)
10-20-2010 11:29 PM
Now I see. Sometimes I'm overthinking this. Need a different approach.