From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search 2d array and replace

Solved!
Go to solution

Hi, I am  fairly new to Labview.

I have an 2D array..

I want to be able to search for column 0 for all values in the array.

If column 0 return values that are the same in previous row, then use the last row.

I'll attach a picture with this so that it will be easier to understand..

 

 

From column 0:

500000 . . . . .

500000 . . . . .

464534 . . . . .

500000 . . . . .

438251 . . . . .

545641 . . . . .

438251 . . . . .

 

There are 2 values of "438251" in that array for column 0. 

There are 3 values of "500000" in that array for column 0.

What can I do to replace the array with something like this..

 

Want to see in the array

 

464534 . . . . .

500000 . . . . .

545641 . . . . .

438251 . . . . .

 

 I need to keep all values in the row that is last the same. I have to delete the whole row values that have same value in column 0. 

 

Can someone point me to the right direction with this..Thanks in Advance!

 

 

 

 

 

 

 

Message Edited by Giangliang on 03-05-2009 08:34 PM
Download All
0 Kudos
Message 1 of 18
(4,663 Views)

I would probably flip the array top to bottom so that I could work from the bottom up.

 

Now that is is flipped.  Keep the first row.

Take the 2nd row, search up to that point. If it doesn't exist append that to the array.  If it did exist, just skip it.

Go on to the 3rd, repeat.

So on until you reach the end of the row.

 

When you are done, flip the array top to bottom.

 

All this could probably be done with only 1 loop.

 

Other alternatives would be to use the delete from array function to delete the duplicate row when you find it.

0 Kudos
Message 2 of 18
(4,645 Views)

Just to add to Raven Fan's reply, OpenG has a Remove Duplicates From 1D Array function that does this for you.  As he mentioned, you'll need to flip the array to keep the last instance of the duplicated elements.  Reverse it again and Bob's your uncle.

 

Message Edited by jcarmody on 03-06-2009 05:13 AM
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Download All
Message 3 of 18
(4,617 Views)

 

I would probably flip the array top to bottom so that I could work from the bottom up.

 

Other alternatives would be to use the delete from array function to delete the duplicate row when you find it.


 

Thanks for the advices. It may sound like a dumb question, but how would I flip the array? i saw reverse1D array...

but  i am working with 2d array right?

 

Message Edited by Giangliang on 03-06-2009 09:26 AM
0 Kudos
Message 4 of 18
(4,601 Views)
With the Reverse 1D Array function.  You can download one of the attached solutions...
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 5 of 18
(4,598 Views)

i am using labview 7.0 right now.

i think the solution you gave needs 8.6 and higher. 

 

0 Kudos
Message 6 of 18
(4,593 Views)

you might not see the vi that i have attached with the question.

i started and didnt know how to finish it..

 

0 Kudos
Message 7 of 18
(4,591 Views)

i think this works...

except for one thing..

i didnt flip it first....

and after the loop...flip it back..

i have to know how to flip the array that ihave first.how would i do that?

 

Message Edited by Giangliang on 03-06-2009 09:51 AM
Download All
0 Kudos
Message 8 of 18
(4,586 Views)

Try this.

 

Note.  The idea I gave above was just one way to do it.  You could also do things such as search from the bottom up.  It's just a matter of how you loop through the array and how you set your indices for starting and stopping searches.  With other methods, it may not be necessary to flip the array.

Message Edited by Ravens Fan on 03-06-2009 11:02 AM
Message 9 of 18
(4,579 Views)

ok...that works...

thanks guys...

my code looks like a mess for doing something like this though...

 

0 Kudos
Message 10 of 18
(4,571 Views)