Thread Subject: mxCreateDoubleMatrix() function

Subject: mxCreateDoubleMatrix() function

From: Geoffroy

Date: 30 Sep, 2009 16:11:00

Message: 1 of 6

I have created a small interface to transfert data between a C++ program and a Matlab workspace. It is working well but I don't know how to create a 3 dimensional matrix to contain a RGB image. I'am able to create and transfert 2D matrix but not a 3D matrix like Im = zeros ( 10, 10, 10 );

How is it possible to do that?

Thank you

Subject: mxCreateDoubleMatrix() function

From: Titus Edelhofer

Date: 30 Sep, 2009 18:16:35

Message: 2 of 6


"Geoffroy " <grsabourin@gmail.com> schrieb im Newsbeitrag
news:h9vvuk$qip$1@fred.mathworks.com...
>I have created a small interface to transfert data between a C++ program
>and a Matlab workspace. It is working well but I don't know how to create a
>3 dimensional matrix to contain a RGB image. I'am able to create and
>transfert 2D matrix but not a 3D matrix like Im = zeros ( 10, 10, 10 );
>
> How is it possible to do that?
>
> Thank you

Hi,
you will need to use mxCreateNumericArray. The doc gives a three dimensional
example.

Titus

Subject: mxCreateDoubleMatrix() function

From: Geoffroy

Date: 1 Oct, 2009 00:33:05

Message: 3 of 6

Yes I have finally found this function but I don't have any result. If I call the function like that

const mwSize dims[]={3,3};
const mwSize NbDimension = 2;
MatlabArray = mxCreateNumericArray( NbDimension, dims, mxUINT16_CLASS, mxREAL );

I put the variable like that
engPutVariable( m_pEngine, in_VarName.c_str(), MatlabArray ) ;

I obtain a 3x3 matrix in the matlab workspace ( only one dimension)

If I try to increase the dimension the function return 0
const mwSize dims[]={3,3};
const mwSize NbDimension = 4;
MatlabArray = mxCreateNumericArray( NbDimension, dims, mxUINT16_CLASS, mxREAL );



"Titus Edelhofer" <titus.edelhofer@mathworks.de> wrote in message <ha07a3$bg6$1@fred.mathworks.com>...
>
> "Geoffroy " <grsabourin@gmail.com> schrieb im Newsbeitrag
> news:h9vvuk$qip$1@fred.mathworks.com...
> >I have created a small interface to transfert data between a C++ program
> >and a Matlab workspace. It is working well but I don't know how to create a
> >3 dimensional matrix to contain a RGB image. I'am able to create and
> >transfert 2D matrix but not a 3D matrix like Im = zeros ( 10, 10, 10 );
> >
> > How is it possible to do that?
> >
> > Thank you
>
> Hi,
> you will need to use mxCreateNumericArray. The doc gives a three dimensional
> example.
>
> Titus
>

Subject: mxCreateDoubleMatrix() function

From: Geoffroy

Date: 1 Oct, 2009 03:19:01

Message: 4 of 6

Yes I have finally found this function but I don't have any result. If I call the function like that

const mwSize dims[]={3,3};
const mwSize NbDimension = 2;
MatlabArray = mxCreateNumericArray( NbDimension, dims, mxUINT16_CLASS, mxREAL );

I put the variable like that
engPutVariable( m_pEngine, in_VarName.c_str(), MatlabArray ) ;

I obtain a 3x3 matrix in the matlab workspace ( only one dimension)

If I try to increase the dimension the function return 0
const mwSize dims[]={3,3};
const mwSize NbDimension = 4;
MatlabArray = mxCreateNumericArray( NbDimension, dims, mxUINT16_CLASS, mxREAL );



"Titus Edelhofer" <titus.edelhofer@mathworks.de> wrote in message <ha07a3$bg6$1@fred.mathworks.com>...
>
> "Geoffroy " <grsabourin@gmail.com> schrieb im Newsbeitrag
> news:h9vvuk$qip$1@fred.mathworks.com...
> >I have created a small interface to transfert data between a C++ program
> >and a Matlab workspace. It is working well but I don't know how to create a
> >3 dimensional matrix to contain a RGB image. I'am able to create and
> >transfert 2D matrix but not a 3D matrix like Im = zeros ( 10, 10, 10 );
> >
> > How is it possible to do that?
> >
> > Thank you
>
> Hi,
> you will need to use mxCreateNumericArray. The doc gives a three dimensional
> example.
>
> Titus
>

Subject: mxCreateDoubleMatrix() function

From: James Tursa

Date: 1 Oct, 2009 05:08:01

Message: 5 of 6

"Geoffroy " <grsabourin@gmail.com> wrote in message <ha1735$j6n$1@fred.mathworks.com>...
> Yes I have finally found this function but I don't have any result. If I call the function like that
>
> const mwSize dims[]={3,3};
> const mwSize NbDimension = 2;
> MatlabArray = mxCreateNumericArray( NbDimension, dims, mxUINT16_CLASS, mxREAL );
>
> I put the variable like that
> engPutVariable( m_pEngine, in_VarName.c_str(), MatlabArray ) ;
>
> I obtain a 3x3 matrix in the matlab workspace ( only one dimension)
>
> If I try to increase the dimension the function return 0
> const mwSize dims[]={3,3};
> const mwSize NbDimension = 4;
> MatlabArray = mxCreateNumericArray( NbDimension, dims, mxUINT16_CLASS, mxREAL );

That's because you are reading beyond the end of valid memory. dims still just has 2 elements the way you have written it, not 4. You need to give dims 4 elements, e.g. dims[] = {3,3,3,3}.

James Tursa

Subject: mxCreateDoubleMatrix() function

From: Ryan Ollos

Date: 1 Oct, 2009 05:08:02

Message: 6 of 6

"Geoffroy " <grsabourin@gmail.com> wrote in message <ha0tc1$nv$1@fred.mathworks.com>...
> Yes I have finally found this function but I don't have any result. If I call the function like that
>
> const mwSize dims[]={3,3};
> const mwSize NbDimension = 2;
> MatlabArray = mxCreateNumericArray( NbDimension, dims, mxUINT16_CLASS, mxREAL );

mwSize ndim = 3
mwSize dims = {10, 10, 10}

That should give you the 10 x 10 x 10 array you referred to in your first example.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com