What is the counterpart of the command (mxSetImagData) that can work for Interleaved Complex API?
조회 수: 3 (최근 30일)
이전 댓글 표시
I need something like:
call mxSetImagData(plhs(1), mxCalloc(n, 8))
and I am using (Interleaved Complex API).
The problem is that (mxSetImagData) is not compatible with Interleaved Complex API.
Therefore, I need the counterpart of (mxSetImagData) which works for the environment (Interleaved Complex API)
댓글 수: 1
James Tursa
2025년 3월 25일
편집: James Tursa
2025년 3월 25일
This question needs more clarity. The mxSetImagData( ) function attaches a pointer to the variable that becomes the imaginary data pointer in the old separate real/imag data model. With interleaved real/imag data model, this makes no sense. So what are you actually trying to do? Turn a real variable into a complex variable? Zero out the imaginary part of an existing complex variable? Attach an existing array to a variable that will become the imaginary data? Or ...?
답변 (1개)
Shantanu Dixit
2025년 3월 24일
편집: Shantanu Dixit
2025년 3월 24일
Hi Magdy,
To the best of my understanding, you are looking for a replacement for 'mxSetImagData' that is compatible with the Interleaved Complex API. Since 'mxSetImagData' only works with the Separate Complex API, it cannot be used in the interleaved representation, where real and imaginary parts are stored together.
In the interleaved Complex API you can use 'mxGetComplexDoubles' to obtain a pointer to the complex data and directly modify the imaginary components.
% For the below code block
plhs[0] = mxDuplicateArray(prhs[0]);
mxDouble *dc = (mxDouble*)mxMalloc(rows*cols*sz);
mxSetImagData(plhs[0], dc);
for (int i = 0 ; i < rows*cols ; i++)
{
dc[i] = i+1;
}
%%%
% Instead use 'mxGetComplexDoubles' for interleaved complex API
plhs[0] = mxDuplicateArray(prhs[0]);
if (mxMakeArrayComplex(plhs[0])) {
mxComplexDouble *dt = mxGetComplexDoubles(plhs[0]);
for (int i = 0 ; i < rows*cols ; i++) {
dt[i].imag = i + 1;
}
}
You can also refer to the extensive documentation provided by MathWorks on Interleaved Complex API and related functionalities:
- Support for interleaved complex API: https://www.mathworks.com/help/matlab/matlab_external/matlab-support-for-interleaved-complex.html
- mxGetComplexDoubles: https://www.mathworks.com/help/matlab/apiref/mxgetcomplexdoubles.html
- maintain complexity of mxArray: https://www.mathworks.com/help/matlab/matlab_external/upgrade-mex-files-to-use-interleaved-complex.html#mw_ed4d89db-745a-413b-a2b7-552bfa0bbcff
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!