Filter löschen
Filter löschen

Mex large output array

2 Ansichten (letzte 30 Tage)
Chris
Chris am 15 Mai 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?

Akzeptierte Antwort

James Tursa
James Tursa am 15 Mai 2013
Bearbeitet: James Tursa am 17 Mai 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 Kommentar
Jan
Jan am 16 Mai 2013
Exactly. When the MEX function should return a matrix, let it return a matrix instead of a set of vectors.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by