LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you do the following array manipulation?

Say I have an array of 5 elments, I want to pull the 5th element out, use that data, after that, i want to use pull the 4th and use the data, then 3rd and so on until all the elements have been used.

 

One way I can think of is to send the array into a for loop and compare the last(5th) element to see if its a 0, if it does not equal 0, then pull this element out and SOMEHOW set the 5th element to 0 AFTER the data has been pulled out. So now, the next iteration will check for 0, and will pull the 4th element since the 5th element is now 0. After taking the data from where the 4th element is, then clear the 4th element to 0. Now continue this until all the data from the array have been used.

 

 

Thank you.

0 Kudos
Message 1 of 11
(2,681 Views)

That's confusing. Your second sentence does not agree with the simple task you ask about in the first sentence. Why are you checking for 0 and replacing non-zero elements? To do what you ask in the first sentence you would just do a reverse arrray and pass that to a for loop.

0 Kudos
Message 2 of 11
(2,678 Views)

It sounds like you are unaware that you can wire an array to a for loop and iterate over each item.

 

Edit: Hit post too soon! Here is the example. I see that Dennis beat me to it Smiley Very Happy

 

Capture.PNG

=====================
LabVIEW 2012


Message 3 of 11
(2,673 Views)

Thank you for the replies.

 

@Dennis: Sorry my post was confusing. I posted what i eventually want to do in the 2nd sentencing, but I also was wondering how to do the things listed in the first sentence.

 

 

@Steve:  At that point, I want to take each data out, and use it outside of the for loop. What you have will iterate over the array one element at a time, but all the data will only stay inside of the for loop, am I correct? What I want is take the data, and wire that to something else, outside of the for loop.

 

Thanks

0 Kudos
Message 4 of 11
(2,662 Views)

 

At what point? You just wire the output of the reverse array around the for loop to where you want to use it. Are you talking about accessing the elements? You can do that with index array.

 

Capture.PNG

=====================
LabVIEW 2012


0 Kudos
Message 5 of 11
(2,654 Views)

Then simply wire the data (unmodified or not) out through the for loop. It will create a new array.

0 Kudos
Message 6 of 11
(2,650 Views)

I've posted a picture using labview, hopefully this will make more sense to the problem im having.

0 Kudos
Message 7 of 11
(2,637 Views)

I strongly recommend you to use MathScript Node if you have.

0 Kudos
Message 8 of 11
(2,603 Views)

 

So you are only interested in the last item? The first section will apply your function to the last item. The second section will apply it to all of the elements.

 

Capture.PNG

=====================
LabVIEW 2012


0 Kudos
Message 9 of 11
(2,592 Views)

Thanks Steve, I did it a different way and I think it might work, not sure yet.....

 I'm actually interested in all of the items BUT I need them going into themath function one at a time. Also, I need to keep result as a number (because it actually gets wired to something else, not shown in example), but the second section will turn that into an array.

 

I have one more question which I believe is pretty simple but I can't figure it out for some reason... 

My question is, I want a number to pass into an array to store, then at a later time, another number will be sent into the same array to store (appending onto the array) (NOTE: all these numbers come from the same source, but this source will change over time due to another function). So after 5 instances, there will be 5 items inside of this array. How do I do this in labview?

 

Thank you!

0 Kudos
Message 10 of 11
(2,579 Views)