LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2D array search

Solved!
Go to solution

@IanSH: i have no coordinates, just indices per row (for the first example) with the "error" of added "0"s because of the array shape


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 11 of 19
(2,023 Views)

@stuleo wrote:

Thanks! I am just discoverying all the nice features of LabVIEW and they are many! I wasn't aware of what concatenating was doing, now it makes sense and it actually looks a lot nicer. I think I did the same in my case by including the if structure to take these in an order. Now, my question goes a little further but I wouldn't like to open another post since we are all on the same page here. If you think I should, please let me know. I want to make a subarray of my elements whose indices are included inside the boarders of the indices I just extracted. I will try some things of my own but I would appreciate any suggestions.


i am not sure i understand correctly:

from your 2D input array you want a 2D subarray,

that has "borders" defined by the found indices?

 

in my exmple above it would be the same, because "2" is in the first column, in the last column and in every row?


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 12 of 19
(2,016 Views)

zort04.png

 

since noone yet ....

quick and "dirty" ... i suppose altenbach flies in in a second and produces a magic micro vi using variants 😉

 

:cheers:


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 13 of 19
(1,999 Views)

Working method using my original index search then using that information:

2D array.PNG

The code in previous post doesn't handle having the extra 2 that I replaced at point 28. The general approach of finding the first instance from each side (I guess thats what's being tried) is a reasonable approach.

Ian
LabVIEW since 2012
Message 14 of 19
(1,989 Views)

with IanSh's method:

zort05.png

 

EDIT: hehe .. you beat me to it 😉


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 15 of 19
(1,986 Views)

@IanSh wrote:

 

 

The code in previous post doesn't handle having the extra 2 that I replaced at point 28. The general approach of finding the first instance from each side (I guess thats what's being tried) is a reasonable approach.


mhh works for me with your DATA, i don't see the error

 

EDIT: yikes .. found it 😉 -- problem seems the 22 position, have to fix


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 16 of 19
(1,984 Views)

fixed it ..

zort06.png

 

@IanSh: thx for pointing out the error

 

regarding the efficiency: if there is only one occurrence of "to find" in the row, all elements will be compared, only if at least two are present, then this solution is faster.

the amount of compares saved should be (last-index-found - first-index-found)

 

to paraphrase peter parker: with complex code comes great confusion 😉

 

:cheers:


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 17 of 19
(1,969 Views)

Sometimes a solution to searching a 2D array can be found by doing a forum search. 😄 No need to re-invent fire.

 

Going back 9 years, you could have found the following two VIs (Yes, today we would use a conditional tunnel as discussed above)...

 

Search2D

 

... and the one doing a 1D search on the flattened 2d array found in the immediately following post.

 

Search2Dalternate

0 Kudos
Message 18 of 19
(1,956 Views)

It didn't come up when I was searching. Thanks for the addition to this post Smiley Very Happy

0 Kudos
Message 19 of 19
(1,946 Views)