# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## 2D matrix merge by skipping elements

Dear all,

I'm trying to merge 4 different 2D matrix into one matrix by skipping elements but unfortunately i have not been able to find skipping mechanism of elements to merge these matrix. Basic example for 2x2 matrix as seen below but real application will be 1824x940 or 1928x1280 and etc. Is there anyone who has an idea?

Message 1 of 11
(1,147 Views)
Solution
Accepted by topic author Hawk_se

## Re: 2D matrix merge by skipping elements

Hi Hawk,

@Hawk_se wrote:

I'm trying to merge 4 different 2D matrix into one matrix by skipping elements but unfortunately i have not been able to find skipping mechanism of elements to merge these matrix. Basic example for 2x2 matrix as seen below but real application will be 1824x940 or 1928x1280 and etc. Is there anyone who has an idea?

Some notes:

• Don't call them "matrix". These are simple 2D arrays!
• Use BuildArray and TransposeArray to combine your 4 smaller arrays into a big one… (After a second look on your expected result you might use other array functions as well.)

Suggestion:

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 2 of 11
(1,123 Views)
Solution
Accepted by topic author Hawk_se

## Re: 2D matrix merge by skipping elements

If you attach your example, I can probably make a solution within minutes!

Make sure to use unique element. Currently, each 2D input array has identical elements and there are several possibilities to get the desired output.  For example the 1111 at position (0,0) of array 1 could end up at (0,0), (0,2), (2,0) or (2,2) and we cannot tell what's correct without making simplifying assumptions.

It is also a bad idea to give an example with square arrays if the real data is not square. Keep the assumptions as small as possible.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 3 of 11
(1,117 Views)
Solution
Accepted by topic author Hawk_se

## Re: 2D matrix merge by skipping elements

@altenbach wrote:

If you attach your example, I can probably make a solution within minutes!.

Looks like I got exactly the same idea as Gerd (assuming the simplest interpretation of the ambiguous problem, see above).

Another assumption are that all input arrays are the same size. If that cannot be guaranteed, you need to add tests and error handling to avoid unexpected results.

There are probably may equally (or even more!) efficient alternatives

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 4 of 11
(1,108 Views)

## Re: 2D matrix merge by skipping elements

Main application is based on gray scale image which includes Bayer pattern. That's why i need to create random numbers for 4 different colour filter to convert to gray scale 16 bits raw image.

Message 5 of 11
(1,102 Views)

## Re: 2D matrix merge by skipping elements

You may consider each 2D arrays as filter and they will be merged into one bigger size of mosaic as seen below. My aim is creating these four (4) 2D arrays by generating random number than merge into one big 2D array by skipping elements in order to create grayscale image.

Message 6 of 11
(1,097 Views)
Solution
Accepted by topic author Hawk_se

## Re: 2D matrix merge by skipping elements

Hi Hawk,

as I wrote before: don't call those 2D arrays - and don't use matrix functions when there is a huge palette of array functions…

Still the same suggestion:

Edit: Christian is right, there's much room for code improvements…

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 7 of 11
(1,092 Views)

## Re: 2D matrix merge by skipping elements

@Hawk_se wrote:

My aim is creating these four (4) 2D arrays by generating random number than merge into one big 2D array by skipping elements in order to create grayscale image.

This is the first time you mention a random number. How does that fit into the problem? (Does each input array have different random numbers which is the same for all elements? Is each element random? etc.?)

Since the green has twice the area, are you somehow accounting for that to get true grey?

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 8 of 11
(1,089 Views)

## Re: 2D matrix merge by skipping elements

What is difference between random number or exact character for an element? The main problem is placing into correct position.

Message 9 of 11
(1,087 Views)

## Re: 2D matrix merge by skipping elements

@Hawk_se wrote:

Main application is based on gray scale image which includes Bayer pattern. That's why i need to create random numbers for 4 different colour filter to convert to gray scale 16 bits raw image.

Why is there so much duplicate code!!!

What are defaults for row&column inputs (currently 0!) and how do the later indices depend on them?

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 10 of 11
(1,086 Views)