Thread Subject: [MEX] mxCreateStructMatrix in Fortran

Subject: [MEX] mxCreateStructMatrix in Fortran

From: Francois Mourougaya

Date: 19 Nov, 2008 13:04:02

Message: 1 of 3

Hello everyone,

I'm having problems using mxCreateStructMatrix.

I created a gateway function in Fortran ("test.F") looking like this :

#include <fintrf.h>
C
C TESTSTRUCT.F - Gateway function for TESTSTRUCT.F

      SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)

      MWPOINTER PLHS(*), PRHS(*)
      INTEGER NLHS, NRHS
      MWPOINTER MXCREATEDOUBLEMATRIX, MXGETPR, MXCREATESTRUCTMATRIX

C VARIABLES DECLARATION
C--------------------------------------------------------------------------
      REAL*4 NBFILD
      CHARACTER*12 FIELDS(6)

C VARIABLES INITIALISATION
C--------------------------------------------------------------------------
      NBFILD= 6
      FIELDS(1)='One'
      FIELDS(2)='Two'
      FIELDS(3)='Three'
      FIELDS(4)='Four'
      FIELDS(5)='Five'
      FIELDS(6)='Six'
      PLHS(1) = MXCREATESTRUCTMATRIX(1, 1, NBFILD, FIELDS)
      
      RETURN
      END

I compiled it using "mex test.F". As you can see, it should do nothing but give back en empty structure matrix, but when I run :
A = test()
Matlab returns :
??? Out of memory. Type HELP MEMORY for your options.

I know for sure it is comming from MXCREATESTRUCTMATRIX (I ran some tests).

Any idea what I'm doing wrong ?

Thanks a lot in advance,
Fran?ois.

Subject: [MEX] mxCreateStructMatrix in Fortran

From: Gadi Reinhorn

Date: 19 Nov, 2008 15:48:03

Message: 2 of 3

Francois,

The third argument needs to be an interger not real.
http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mxcreatestructmatrix.html

Change
REAL*4 NBFILD
to
INTEGER*4 NBFILD

I made this change and got your test to work.

Hope that helps,
Gadi


"Francois Mourougaya" <framou1980@yahoo.fr> wrote in message
news:gg12s2$ajt$1@fred.mathworks.com...
> Hello everyone,
>
> I'm having problems using mxCreateStructMatrix.
>
> I created a gateway function in Fortran ("test.F") looking like this :
>
> #include <fintrf.h>
> C
> C TESTSTRUCT.F - Gateway function for TESTSTRUCT.F
>
> SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
>
> MWPOINTER PLHS(*), PRHS(*)
> INTEGER NLHS, NRHS
> MWPOINTER MXCREATEDOUBLEMATRIX, MXGETPR, MXCREATESTRUCTMATRIX
>
> C VARIABLES DECLARATION
> C--------------------------------------------------------------------------
> REAL*4 NBFILD
> CHARACTER*12 FIELDS(6)
>
> C VARIABLES INITIALISATION
> C--------------------------------------------------------------------------
> NBFILD= 6
> FIELDS(1)='One'
> FIELDS(2)='Two'
> FIELDS(3)='Three'
> FIELDS(4)='Four'
> FIELDS(5)='Five'
> FIELDS(6)='Six'
> PLHS(1) = MXCREATESTRUCTMATRIX(1, 1, NBFILD, FIELDS)
>
> RETURN
> END
>
> I compiled it using "mex test.F". As you can see, it should do nothing but
> give back en empty structure matrix, but when I run :
> A = test()
> Matlab returns :
> ??? Out of memory. Type HELP MEMORY for your options.
>
> I know for sure it is comming from MXCREATESTRUCTMATRIX (I ran some
> tests).
>
> Any idea what I'm doing wrong ?
>
> Thanks a lot in advance,
> Fran?ois.

Subject: [MEX] mxCreateStructMatrix in Fortran

From: Francois Mourougaya

Date: 19 Nov, 2008 15:57:02

Message: 3 of 3

Thanks a lot ! What a stupid mistake !

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

Contact us at files@mathworks.com