Source-list - goal is a matrix - convert matrix - Find a good way

Markus Freitag 3,786 Reputation points
2022-02-12T09:53:27.257+00:00

Hello,

I need your help.

I have a list, like this.
For this I have to analyze a matrix
In the example a 5.3 matrix.

Pos	Row	Column	x	y	State	Counter	Coding  
1	1	1	10	10	1	32321	0000  
2	2	1	20	10	1	32322	0000  
3	3	1	30	10	1	32323	0000  
4	4	1	40	10	0	32324	FFFF  
5	5	1	50	10	1	32325	0000  
6	1	2	10	110	1	32326	0000  
7	2	2	20	110	1	32327	0000  
8	3	2	30	110	1	32328	0000  
9	4	2	40	110	1	32329	0000  
10	5	2	50	110	1	32330	0000  
11	1	3	10	210	1	32331	0000  
12	2	3	20	210	1	32332	0000  
13	3	3	30	210	0	32333	FFFF  
14	4	3	40	210	1	32334	0000  
15	5	3	50	210	1	32335	0000  
  
The result should be  
0000 0000 0000  
0000 0000 0000  
0000 0000 FFFF  
FFFF 0000 0000  
0000 0000 0000  
  
  
Now the hard part. I have to create a 3.5 matrix from the 5.3 matrix, I have to convert.  
0000 0000 0000 FFFF 0000  
0000 0000 0000 0000 0000  
0000 0000 FFFF 0000 0000  
  
  
Finally I have to write it in an xml element  
  
<Result bin1="0000 0000 0000"  
        bin2="0000 0000 0000"  
        bin3="0000 0000 FFFF"  
        bin4="FFFF 0000 0000"  
        bin5="0000 0000 0000"  
\>  
    <ResultConvert bin1="0000 0000 0000 FFFF 0000"  
                   bin2="0000 0000 0000 0000 0000"  
                   bin3="0000 0000 0000 0000 0000" \>  

The questions
How do I do it?
Which objects are suitable?
Datatable?

Can someone show me? Thanks in advance.

173717-matrix-5-3-convertto-3-5-1.png

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,862 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,457 questions
0 comments No comments
{count} votes

Accepted answer
  1. P a u l 10,406 Reputation points
    2022-02-12T14:54:38.903+00:00

    You can just use a standard 2D array to represent your data (or rather, an array of arrays.) If your data is coming from a SQL table like in the first example then you'll need to convert that serial one-dimensional data into your 5x3 matrix.

    From there it's fairly straight forward. You just need to create a new 2D array with flipped row/column dimension sizes, then map over the data to the corresponding cell. In matrix terms this is called transposing. Here's a snippet to demonstrate:
    https://pastebin.com/yDJTmAKg

    (had to pastebin because of too many characters)

    Result:

    <?xml version="1.0" encoding="utf-16"?>
    <Result
      bin0="0000 0000 0000"
      bin1="0000 0000 0000"
      bin2="0000 0000 FFFF"
      bin3="FFFF 0000 0000"
      bin4="0000 0000 0000">
      <ResultConvert
        bin0="0000 0000 0000 FFFF 0000"
        bin1="0000 0000 0000 0000 0000"
        bin2="0000 0000 FFFF 0000 0000" />
    </Result>
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful