cancel
Showing results for 
Search instead for 
Did you mean: 

2D array search

SOLVED
Highlighted
jwscs
Active Participant

Re: 2D array search

@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.
jwscs
Active Participant

Re: 2D array search


@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.
jwscs
Active Participant

Re: 2D array search

Message contains an image Message contains an attachment

zort04.png

 

since noone yet ....

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

 

:cheers:


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
IanSh
Member

Re: 2D array search

Message contains an image Message contains an attachment

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
jwscs
Active Participant

Re: 2D array search

Message contains an image Message contains an attachment

with IanSh's method:

zort05.png

 

EDIT: hehe .. you beat me to it Smiley Wink


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
jwscs
Active Participant

Re: 2D array search


@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 Smiley Wink -- problem seems the 22 position, have to fix


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
jwscs
Active Participant

Re: 2D array search

Message contains an image Message contains an attachment

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 Smiley Wink

 

:cheers:


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
altenbach
Knight of NI

Re: 2D array search

Message contains a hyperlink Message contains an image

Sometimes a solution to searching a 2D array can be found by doing a forum search. Smiley Very Happy 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

stuleo
Member

Re: 2D array search

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