Borrar filtros
Borrar filtros

Mex large output array

2 visualizaciones (últimos 30 días)
Chris
Chris el 15 de Mayo de 2013
Hi,
I want to have the output from my mex function stored in one large array, something like:
[output(:,:)] = mexfunction(input)
I have it working where I am receiving my output but I have to have the individual outputs listed
[y1,y2,y3...] = mexfunction(input)
I am using mxcopyreal8toptr to transfer the output back to matlab. Is there a different command I need to use to store in one large array?

Respuesta aceptada

James Tursa
James Tursa el 15 de Mayo de 2013
Editada: James Tursa el 17 de Mayo de 2013
You have to combine the data into one array inside the mex routine itself. Once outside the mex routine, if all you have is the y1, y2, etc variables then you will have to manually concatenate them together (which will involve a data copy of course). I am guessing this is possible inside the mex routine with the mxCopyReal8ToPtr function (passing a pointer to the middle of a memory block) but confess I haven't tried it ... you may get an assert fault. If you do get a fault there are ways around it. Let me know if you need help with this.
EDIT
I just ran a test and mxCopyReal8ToPtr does not generate an assert fault if passed an address in the middle of a memory block. So a code snippet example for doing this is:
mwPointer mxCreateDoubleMatrix
mwPointer mxGetPr
:
mwPointer pr
real*8 x(3), y(3) ! start with two separate Fortran variables
mwSize m, n
integer*4 complexity
:
x = [1,2,3]
y = [4,5,6]
m = 3
n = 2
complexity = 0
plhs(1) = mxCreateDoubleMatrix(m,n,complexity)
pr = mxGetPr(plhs(1)) ! point to 1st column
call mxCopyReal8ToPtr(x,pr,m) ! copy into the 1st column
pr = pr + m*8 ! pointer arithmetic, point to 2nd column
call mxCopyReal8ToPtr(y,pr,m) ! copy into the 2nd column
  1 comentario
Jan
Jan el 16 de Mayo de 2013
Exactly. When the MEX function should return a matrix, let it return a matrix instead of a set of vectors.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by