LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array questions

My question has to do with accessing all of the elements of an array. I have attached a portion of my code that shows what I need help with, as my main VI is much larger. I’d like to compare the values in the array with the iteration number of my big while loop. This big while loop contains code within a stacked sequence structure. When the element in the array and the iteration number are equal, a frame that contains a case structure would execute a true case. Otherwise, the false case would run, which would contain nothing, or no relevant code I need. I cannot figure out how to gain access to all of the elements or numbers in the array, instead I can only get one of the numbers. I’m not sure if there is a better way to do this or not. I’m still rather new to Labview. My For loop provides a counter which provides multiples of the number that is specified and in turn provides the number to be compared (if I could get it from the array).

Any help anyone could provide, I would be most grateful.

Thnaks…

e-mail at: haffey811@aol.com
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 1 of 16
(4,352 Views)
Do I understand correctly that you want to check if the iteration number of the big loop occurs somewhere in the array?

If that is the case, you can use the 'Search 1D array' function (from the Array function palette) as is shown in the attached code snippet
0 Kudos
Message 2 of 16
(4,348 Views)
Simply feed the entire array to the "equal?" operation, then feed the resulting boolean array to "Or array elements" (from the boolean palette). It will output true if at least one of the array elements is equal to your comparison number. (see attached image).
Message 3 of 16
(4,188 Views)
Thanks altenbach! This is exactly what I needed and it seems to do the trick. I didn't even relaize that function was on that palette.

Thanks again...
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 4 of 16
(4,139 Views)
Thanks fahlers for the suggestion. I'll keep it in mind as it might do the trick. I think for right now I'll go with what altenbach suggested though.


Thanks again for your help...
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 5 of 16
(4,315 Views)
Fahlers and my suggestion are functionally equivalent.

If you are dealing with really huge arrays, fahlers's method is probably more efficient, especially if a match is found early in the array.

Mine is more generic and probably easier to understand if you look at the diagram two years from now. 😉 It can also easily be modified for other comparison operations, e.g. if you need to check if at least one array element is larger than "i" for example (not possible using "search array").

You pick! 🙂
0 Kudos
Message 6 of 16
(4,109 Views)
Actually one doesn't need to build the array in order to search through it or compare with it, as the following snippet shows:
0 Kudos
Message 7 of 16
(4,081 Views)
Thanks again for replying guys. I'll try out all of the suggestions. My array will end up being rather large I think, since my main vi will be running for a long period of time possibly. I'll need the array to be large to get the job done, not the size I showed in the example. But I'll test both out and see what works.

Thanks again for your help, any other suggestions would be welcome as well.

e-mail at: haffey811@aol.com
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 8 of 16
(4,002 Views)
Hello again, I had another question that is somewhat related I think to this topic. I have attached a piture of my code to hopefully help with my explanation. I'm trying to execute some code contained in a case structure again, that would save my acquired spectra. The loop it is in will run continuous. I'd like to save a certain number of the spectra whenever I want, whether the loop is on it's 100th iteration or 10th. So if I'd want to save 25 spectra I could or if I wanted to save 5, I could do that, no matter how the loop is running. The code inside the case structure could be executed a the push of a save button and would save the preset number. I tried using a for loop around the save code, but this doesn't quite work right, as it saves the same file for whatever number is set. I've also tried using the while loop as a counter via the "i" icon to count the iterations. This seem to work, althought I can't get the saving down right whenever I want and to get it to stop. I need it to save for the preset number and then stop.

If anyone has any ideas or suggestions about how to do this, I'd appreciate it a lot. If any further code or explanation is needed, please let me know.

Thanks...
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 9 of 16
(4,177 Views)
Please attach the picture of your code as promised. Somehow, it did not make it.
0 Kudos
Message 10 of 16
(4,137 Views)