LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting 2x2 array from 10x10 array Using only for loops

Solved!
Go to solution

Hi all ,

 


I have this assignment for "pattern matching" - user enters 2x2 boolean pattern, and i have to compare and find it in larger random 10x10 boolean array.
I managed to do it with the array palette, but my instructor alert me that for this assignment we are forbid to use this palate and only use "basic" functions.
So i'm trying to follow my solution and exact 2x2 array from the large array , but I stumble in the "well known" problem with loops as I can see by searching in google - I want that the loop will start from different 'i' , this for extracting every iteration 2x2 array from different location from the bigger array.

 

 

any help is appreciated ,

 

0 Kudos
Message 1 of 16
(3,805 Views)

Without using only basic functions. Well that's annoying! 

How would I go about it:

you have 81 different positions you need to look at:

0    1    2    3    4    5    6    7    8    9

10  11 12 13 14 15......

                                                   ......81

for position 3 you know you need to look at 2D index

(0,3)  (0,4)

(1,3)  (1,4)

 

So have a for loop running 81 times, recover (row, column). Then it's just 

(row, column)                 (row, column+1)

(row+1, column)            (row+1, column+1)

for each iteration of loop. 

Compare each value to user defined pattern and if they are all the same you've matched the pattern (index all results)! 

Use nested loops to convert from a 1d array of 81 bool results to your indication array. 

 

But it'll be annoying to pull it off. Good luck. 

 

(extra hint: quotient & remainder vi might be of help....)

0 Kudos
Message 2 of 16
(3,788 Views)

Hi, 

 

"So have a for loop running 81 times, recover (row, column). Then it's just 

(row, column)                 (row, column+1)

(row+1, column)            (row+1, column+1)

for each iteration of loop. 

Compare each value to user defined pattern"

 

this is great way to find 2x2 indices, didn't thought of it, 

So I have this loop that run up to 81, within I keep track on those indices - 

(row, column)                 (row, column+1)

(row+1, column)            (row+1, column+1)

 

but how do I address them to the array ? meaning how can I see the values that are in those indices ? 

 

 

0 Kudos
Message 3 of 16
(3,774 Views)

UdiWeiss wrote:

but how do I address them to the array ? meaning how can I see the values that are in those indices ?


Index Array.  That function is as basic as it gets.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 16
(3,767 Views)
😕 nop , not allowed to use the array palette.
0 Kudos
Message 5 of 16
(3,759 Views)

@UdiWeiss wrote:
😕 nop , not allowed to use the array palette.

I'm sorry.  But you have an array.  Therefore you have to use something in the array pallette.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 16
(3,754 Views)

@crossrulz wrote:

@UdiWeiss wrote:
😕 nop , not allowed to use the array palette.

I'm sorry.  But you have an array.  Therefore you have to use something in the array pallette.


I totally agree that this should be done with the array palette and I don't quite see the point of not using it.

 

Without using the array palette it can be done using 3 2D picture functions: Flatten Pixmap.vi, Get Image Subset.vi and Unflatten Pixmap.vi (using the 1-bit pixmap). Use the Get Image Subset to extract a 2x2 array. Compare the unflatten extracted 1-bit pixmap to your 2x2 pattern.

 

Ben64

Message 7 of 16
(3,737 Views)

Can't use your Index array!?!

That's like saying you can't use the add function. 

 

Cheat - make your own index array subvi.

For loop with conditional terminal, auto-indexing in and last value out, with the condition of stop being if For loop index = row index input. Since it is set to last value out it will give you your 1d row from 2d array. Then have another for loop afterwards with same characteristics except conditional stop when index = column index input.

This will give you out a single element of (row index, column index) from a 2d array in. Your teacher can't complain at that one!

 

 

Message 8 of 16
(3,722 Views)

I'll won't complete your assigment, but here the trick.

 

You now just have to find what boolean operator,

where to place it and how to concatenate each

lines to sum (hint hint hint) the boolean arrays to

get the final result.

 

Good luck !

 

David Koch

 

PS : Yeah, of course the final array is narrower

as the first line and first column are used to match.

But there is a bug if the 'User Defined Pattern' is

1x1 because it should match the 'Random Array'

size. Will you find it ?

Message 9 of 16
(3,718 Views)

Well, this is not a LabVIEW problem, but a puzzle, then.

 

Autoindexing is an array function, why should it be allowed? We need a complete list of allowed functions.

 

If autoindexing is allowed, I would just use a shift register in the inner and outer loop, giving access to the last two values in each dimension that then can be compared with the four values from the pattern.

 

(Beside, even your disallowed example code seems overly complicated! For example your inner two for loops and associated code could be replaced by a simple "eqaul" in compare aggregates" mode! See also here :D)

Message 10 of 16
(3,707 Views)