[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Concatonation of Matrices in octave API HOW?
From: |
Stefan van der Walt |
Subject: |
Re: Concatonation of Matrices in octave API HOW? |
Date: |
Thu, 9 Jun 2005 09:02:27 +0200 |
User-agent: |
Mutt/1.5.6i |
Hi John
First, create an ND array of the appropriate size, then add your
result matrices.
int nr_results = 10;
int rows = 5;
int cols = 5;
NDArray nda(dim_vector(rows, cols, nr_results));
Array<int> dim(3,0);
for (int i = 0; i < nr_results; i++) {
// generate a matrix
Matrix A(rows, cols, 0);
A(0,0) = i;
// append the matrix
dim(2) = i;
nda = nda.concat(A, dim);
}
This code should give
ans(:,:,1) =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
ans(:,:,2) =
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
etc.
Regards
Stefan
On Wed, Jun 08, 2005 at 08:06:08PM -0500, John Weatherwax wrote:
> Hello,
> I have several matrices, each one represents the solutions to a system of
> PDE's at several timesteps. I currently get each one by a call to a
> fortran subroutine that integrates the PDE from time t_{n} to time t_{n+1}.
> I would like to be able to "concatonate" these matrices into a NDArray (or
> similar) structure to then pass out of the C++ gateway routine I have
> written that interfaces with the fortran code but I cannot seem to be able
> to figure out how to do this. What I need is something like:
>
> NDArray uAll;
> for( int i=1; i<=nTimesteps; i++){
> Matrix uOneStep( numberOfPDEs, numberOfGridPts );
> double* uOneStepP = uOneStep.fortran_vec();
> F77_FUNC(pdecode,PDECODE)(uOneStepP,... other args...)
> uAll.insert( uOneStep )
> }
> return uAll;
>
> Thus uAll would have its "page" dimension each timeslice. This may not be
> the best way to do this. Any "other" method to get this multidemisional
> information out would be helpful too.
>
> TIA,
>
> Wax
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------