上使用MEX整型数组 [英] using integer arrays on mex

查看:206
本文介绍了上使用MEX整型数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想传递一个整数数组从MATLAB到C.
我已经使用类型uint64_t中尝试,但它不断崩溃。
获取使用mxGetPr()双指针正常工作,但我需要强制转换的内容转换成整数,并在每次迭代这样做可能会很慢。

I want to pass an integer array from MATLAB to C. I've tried using the type uint64_T but it keeps crashing. Getting a double pointer using mxGetPr() works fine, but I need to typecast the content into an integer and doing so in every iteration might be slow.

我在mexFunction尝试这样做:

I've tried this in the mexFunction:

uint64_T *l;
l= (uint64_T *)mxGetData(prhs[1]);

在调用此变量的函数是这样的形式:

The function calling this variable is of this form:

void XAction( const double *v, const uint64_T *l, double *w)
{
for (j=c; j; j--)
    for (i=r-1; i; i--)
        w[i] =v[l[r*j +i]]
}

我在的铸字犯了一个错误?

Am I making a mistake in the typecasting?

我已经看到了这样的回答:如何解读在MEX-功能整数数组,但我一直没能取得进展。

I've seen this answer : how to read an integer array in MEX-function but I haven't been able to make progress.

推荐答案

有关 L =(uint64_t中*)mxGetData(prhs [1]); 正确,工作您MEX从MATLAB传递的数据已经为类型UINT64的。
请确保您传递UINT64阵列从MATLAB到您的MEX文件。如果你调用 MYMEX([1 2 3])传递的数组不是整数。它是双。

For l= (uint64_T *)mxGetData(prhs[1]); to work correctly, the data passed from MATLAB to your mex already has to be of type uint64. Make sure you are passing uint64 array from MATLAB to your mex file. If you call myMex([1 2 3]) the array passed is not integer. It is double.

您不能转换双阵列通过铸造指针int数组。要么你必须通过从MATLAB整数值或你必须创建一个新的int数组,并通过单独铸造每个值填充在一个周期。要转换的值在MATLAB中UINT64,你可以做 MYMEX(UINT64([1 2 3]))

You can't convert a double array to int array by casting the pointer. Either you have to pass integer values from MATLAB or you have to create a new int array and fill it in a cycle by casting each value individually. To convert values to uint64 in MATLAB, you can do myMex(uint64([1 2 3]))

这篇关于上使用MEX整型数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆