フィルターのクリア

Mex large output array

2 ビュー (過去 30 日間)
Chris
Chris 2013 年 5 月 15 日
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?

採用された回答

James Tursa
James Tursa 2013 年 5 月 15 日
編集済み: James Tursa 2013 年 5 月 17 日
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 件のコメント
Jan
Jan 2013 年 5 月 16 日
Exactly. When the MEX function should return a matrix, let it return a matrix instead of a set of vectors.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by