# HELP:Saving a row of a 2D matrix in a cell of 1D matrix

Page 1 of 1

## 4 Replies - 458 Views - Last Post: 23 October 2015 - 04:57 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=383458&amp;s=f6ea300e1f434e7c49e26a38a3c75db7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 kwnnayo

Reputation: 0
• Posts: 3
• Joined: 23-October 15

# HELP:Saving a row of a 2D matrix in a cell of 1D matrix

Posted 23 October 2015 - 02:13 AM

Hello everyone! I have this problem here:

Let's say that I have this matrix A :

-3 0 1
1 2 0
0 1 0

And i want to create an other matrix B[3] with:
B[0]:contains whole first row of A ,A[0,0] to A[0,2]
B[1]:contains whole second row of A, A[1,0] to A[1,2]
and so on.

Is there any possible way to do this? Thank you

Is This A Good Question/Topic? 0

## Replies To: HELP:Saving a row of a 2D matrix in a cell of 1D matrix

### #2 horace

• D.I.C Lover

Reputation: 768
• Posts: 3,832
• Joined: 25-October 06

## Re: HELP:Saving a row of a 2D matrix in a cell of 1D matrix

Posted 23 October 2015 - 03:08 AM

clearly B[0] has to have some data structure to contain the elements a[0][0], a[0],[1], a[0][2]
B could be a structure (or a class in C++) which contains an array (or a vector in C++perhaps could you clarify what you are atempting to do?

### #3 kwnnayo

Reputation: 0
• Posts: 3
• Joined: 23-October 15

## Re: HELP:Saving a row of a 2D matrix in a cell of 1D matrix

Posted 23 October 2015 - 03:42 AM

I have 2 2D arrays. I want to create 2 1D arrays that the elements of the 1D arrays contain the rows of the 2Ds.
Then, I want to combine the 2 1D arrays to make a 2D array.

Lets say we have:

1 2 3
Array A: 4 5 6
7 8 9

Array B: 10 11 12
13 14 15
16 17 18

I want the (1,2,3) , (4,5,6) , (7,8,9) to be the elements of one array C[3]
with C[0]=[1,2,3], C[1]=[4,5,6], C[2]=[7,8,9].

Same goes for Array B, I want to have an array D[3] with
D[0]=[10 11 12], D[1]=[13 14 15], D2=[16 17 18].

Then I wanna create a final 2D array E[2][3] with E[0][0] = D[0], E[0][1]=D[1]......E[1][2]=D[2].

I'm using C++ by the way.

### #4 horace

• D.I.C Lover

Reputation: 768
• Posts: 3,832
• Joined: 25-October 06

## Re: HELP:Saving a row of a 2D matrix in a cell of 1D matrix

Posted 23 October 2015 - 04:36 AM

using C you could use a struct, e.g.
```typedef struct Btype
{int data[20];};

int main(void)
{
int i, a[3][3];
struct Btype b[3];
for(i=0;i <3; i++)
b[0].data[i]=a[0][i];
}

```

in C++ you could use a class

### #5 kwnnayo

Reputation: 0
• Posts: 3
• Joined: 23-October 15

## Re: HELP:Saving a row of a 2D matrix in a cell of 1D matrix

Posted 23 October 2015 - 04:57 AM

horace, on 23 October 2015 - 04:36 AM, said:

using C you could use a struct, e.g.
```typedef struct Btype
{int data[20];};

int main(void)
{
int i, a[3][3];
struct Btype b[3];
for(i=0;i <3; i++)
b[0].data[i]=a[0][i];
}

```

in C++ you could use a class

Ahaaa!! I understood it!!! Thank you very very much!!!