4 Replies - 475 Views - Last Post: 23 October 2015 - 04:57 AM Rate Topic: -----

#1 kwnnayo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • 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?
Was This Post Helpful? 1
  • +
  • -

#3 kwnnayo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

Hi, thanks for your time :)

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.
Was This Post Helpful? 0
  • +
  • -

#4 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • 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
Was This Post Helpful? 1
  • +
  • -

#5 kwnnayo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

View Posthorace, 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!!! :innocent:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1