Hi everyone,

i have a problem with constructing a big matrix from small matrices. could you please help me figure out?
my problem is:
i now have 200 matrices (1000 x 5) => i now want to build them in a big matrix (1000x1000 =(5 x 200)) just store the column of small matrices in to columns of big matrix. as my following code.
So could you take a look and help me figure out?

for(m=1;m<=200;m++){
		for(j=0; j<=d+8; j++) {
			for(i=0; i<=l+8; i++) {
				for(k=1; k<=TSpcs+3; k++){
					U2[(m-1)*TSpcs +k][i][j] = U1[m][k][i][j] - U_mean[k][i][j];
				}
			}
		}
	}

Thanks for your kindly and help,

BOMTK,

It's a rather strange snipped: a matrix is a 2D rectangualar array but the code uses three indicies and has a lot of magic numbers (+8, +3 etc)...

If you want to collect a real 2D matrix 1000x1000 (of doubles, for example), look at this code sceleton:

double** bigmat;
// Suppose we have initialized all matrix row pointers properly...
double** psmall;

for (int m = 0, k = 0; m < 200; ++m, k += 5)
{
    /// set psmall to the next small matrix

    for (int i = 0; i < 1000; ++i)
        for (int j = 0; j < 5; ++j)
            bigmat[i][k+j] = psmall[i][j];
}

Remember: rows => 1st index, columns => 2nd index...

Thanks you very much.
I already fixed that problem with your your advices
Here is my code,

for (m=1, k=0; m<=21; ++m, k +=TSpcs+3){
		for(j=0; j<=d+8; ++j) 
			for(i=0; i<=l+8; ++i) 
				for(int n=1; n<=TSpcs+3; ++n)

					U2[k+n][i][j] = Usnap[m][n][i][j];
	}

Please, make your secret public: why your "matrix" has 3 or 4 indicies?
I see you have another troubles (posts) with this code.
May be better present your data declaration and initialization code...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.