LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Haw to find element in array which occurs only once

Solved!
Go to solution

I have 2d array like this one:

 

1 2 3 4 5 0

5 6 2 4 7 2

8 3 6 0 9 4

5 6 7 7 3 2

 

And I need to find elements which appears only once in this array

In this case 8 and 9

I also need position of this elements (row and column)

Numbers are integers

 

I tried to reshape array and use find element but no results.

 

0 Kudos
Message 1 of 14
(3,674 Views)
Please attach your failed attempt and we will tell you what the problem might be. Are all numbers single digit? Is this homework?
0 Kudos
Message 2 of 14
(3,656 Views)

I tried to find indexes of each elements:

 

bad.jpg

 

and later i wanted to get element that has only one index

 

 

but i think now that this is a bad aproach for this problem

0 Kudos
Message 3 of 14
(3,622 Views)

Hi pawhan11,

you can create a histogram from your data, there are functions in LabVIEW to do it, and a lot more around here in the forum. If you have the histogram, then you can search the elements with the value "1". The last step is to search them again in your array to get the position.

 

Hope it helps.

Mike

0 Kudos
Message 4 of 14
(3,612 Views)
Solution
Accepted by pawhan11

Your best bet is to reshape to a 1D array to do your seaching and use "Quotient & Remainder" to convert the location (index) in the 1D array back to the index in the 2D array. Use "Array Size" to get the number of rows and cols of the 2D array.

 

The Histogram only works on 1D arrays.

 

Or reshape to a 1D array. For each digit (0-9) use "Search 1D Array" twice. If the first "Search" finds a match (not= -1), use the offset to start the 2nd search past the index of the 1st find. If 2nd "Search" does return a -1 then it occurs ONE and only ONE time

Use the index from the first "Search" to calculate the index ("Quotient & Remainder") Row and Col in the 2D array. 

Omar
0 Kudos
Message 5 of 14
(3,596 Views)

@Omar II wrote:
 

Or reshape to a 1D array. For each digit (0-9) use "Search 1D Array" twice. If the first "Search" finds a match (not= -1), use the offset to start the 2nd search past the index of the 1st find. If 2nd "Search" does return a -1 then it occurs ONE and only ONE time

Use the index from the first "Search" to calculate the index ("Quotient & Remainder") Row and Col in the 2D array. 


 

So obvious solution ..... Smiley Very Happy

 

Big hanks

0 Kudos
Message 6 of 14
(3,586 Views)

Here's a solution that should work for you.  Sorry, ignore the Abort.zip.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Download All
0 Kudos
Message 7 of 14
(3,575 Views)

From the original description, is is not absolutely clear if a small array of all possible values is provided. If is is not, here's a quick draft for random integer ranges. I also included a table where all unique values are highlighted with a different background color. Just to give you some ideas.... 😉

 

 

Message 8 of 14
(3,550 Views)

@altenbach wrote:

From the original description, is is not absolutely clear if a small array of all possible values is provided. If is is not, here's a quick draft for random integer ranges. I also included a table where all unique values are highlighted with a different background color. Just to give you some ideas.... 😉

 

 


Thanks 🙂

 

Just to be  100% sure, one small question:

 

[-2 -2] allows You to modify all elements of table at once??

0 Kudos
Message 9 of 14
(3,533 Views)

 

altenbach wrote

From the original description, is is not absolutely clear if a small array of all possible values is provided.


From the first post I too though the same thing. But from his 2nd post with his code posted, he is providing a search array with digits 0-9.

 

I teach a LabVIEW class and one of the assignments I give the students is a sudoku solver (looking for digits 1-9).

So along some of the solutions for that.

 

Search for not matching.png

Omar
0 Kudos
Message 10 of 14
(3,531 Views)