필터 지우기
필터 지우기

matlab mex in-place editing via "mxUnshareArray" or similar functionality

조회 수: 10 (최근 30일)
Nikolaus Smith-Simmons
Nikolaus Smith-Simmons 2023년 12월 12일
편집: James Tursa 2023년 12월 14일
Hello,
I'm trying to pass the reference for a matlab array and modify that array in place within the mex function. It seems that Matlab used to have this functionality, but that it was deprecated in 2015b. Currently, the input prhs[n] is temporary in scope, and changes that I make to that pointer are not reflected in matlab. My current implementation uses: mxComplexDouble * output_array = mxGetComplexDoubles(plhs[0]); then populates the output_array; and at the close of each mex call, it seems a relatively expensive copy operation is being performed.
It seems matlab used to support the capability to pass by reference and unshare the reference if modifications were needed. Is there still any way to do this? https://undocumentedmatlab.com/articles/matlab-mex-in-place-editing
vectorization in matlab is much slower than the C mex function which uses fixed-point representation to speed up calculations
i'm working to pre-allocate the output array now, but i would still really like to be able to write directly to the output array via the C mex function

답변 (1개)

James Tursa
James Tursa 2023년 12월 14일
편집: James Tursa 2023년 12월 14일
So, MATLAB has never officially supported modifying input variables in-place in a mex routine. There are potential side effects of modifying shared variables. There are/were some undocumented API functions and hacks that could let you do this in an unofficial manner to try and avoid the side effects, and maybe that is what you are referring to. But many of these undocumented functions have disappeared from the API or are prevented from linking with your code, so that is harder to do currently.
You will need to post a small example that reproduces your problem. I am unaware of anything that would prevent you from modifying a prhs[ ] variable in-place as long as you accept the risk of side effects. Your post mentions plhs[ ] and not prhs[ ], so I am unsure what you are really trying to do here.

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by