cancel
Showing results for 
Search instead for 
Did you mean: 

search 2d array and replace

SOLVED
Giangliang
Member
Solved!

search 2d array and replace

Message contains an image Message contains an attachment

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
17 REPLIES 17
RavensFan
Knight of NI

Re: search 2d array and replace

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.

jcarmody
Trusted Enthusiast

Re: search 2d array and replace

Message contains an image Message contains an attachment

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

Giangliang
Member

Re: search 2d array and replace


 

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
jcarmody
Trusted Enthusiast

Re: search 2d array and replace

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

Giangliang
Member

Re: search 2d array and replace

i am using labview 7.0 right now.

i think the solution you gave needs 8.6 and higher. 

 

Giangliang
Member

Re: search 2d array and replace

Message contains an attachment

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

i started and didnt know how to finish it..

 

Giangliang
Member

Re: search 2d array and replace

Message contains an image Message contains an attachment

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
RavensFan
Knight of NI

Re: search 2d array and replace

Message contains a hyperlink Message contains an image Message contains an attachment

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
Highlighted
Giangliang
Member

Re: search 2d array and replace

Message contains an attachment

ok...that works...

thanks guys...

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