matlab中访问数组,如何在mex文件中访问Matlab数组结构中的数据

我正在编写一个C mex函数,以提高更大的matlab代码的性能 . 作为mex函数的一部分,我试图从在MATLAB中创建的结构数组中读取 . 数组中的每个项都包含一个由复数数组组成的结构 . 我正在编写的代码理想地单独访问数组中的每个结构 .

我试图编写的函数将传递整个数据结构和数组索引 . 使用该信息,我想获得指向该数组索引的matlab结构中复数数组的实部和虚部的指针 .

我完全接受我不了解如何在c / c mex文件中读取MATLAB结构 .

这就是我的尝试

void read_struct(int i, const mxArray* AoS, double *real, double *imag)

{

/*

read_struct: reads real and imaginary parts of complex number array from

within a Matlab Structure within an array of Structures.

INPUTS: i = index of the structure to be accessed

AoS = Array of Structures

OUTPUTS: real - pointer to real part of complex number array

imag - pointer to imaginary part of complex number array

*/

// Declare pointers to mxArray

const mxArray *p_ph_F1, *p_ph_XF1, *p_ph_F2, *p_ph_YF2, *p_ph_F3, *p_ph_ZF3,

*p_ph_F4, *p_ph_XF4, *p_ph_F5, *p_ph_YF5, *p_ph_F6, *p_ph_ZF6;

// Declare pointers to real and imaginary parts of Matlab Complex values

// Real Parts

double *p_ph_F1_r, *p_ph_XF1_r, *p_ph_F2_r, *p_ph_YF2_r, *p_ph_F3_r, *p_ph_ZF3_r,

*p_ph_F4_r, *p_ph_XF4_r, *p_ph_F5_r, *p_ph_YF5_r, *p_ph_F6_r, *p_ph_ZF6_r;

// Find pointer to correct array cell

const mxArray* ph = mxGetCell(AoS, i);

//Pointers to complex number arrays

p_ph_F1 = mxGetField(ph,0,'ph_F1');

p_ph_XF1 = mxGetField(ph,1,'ph_XF1');

p_ph_F2 = mxGetField(ph,2,'ph_F2');

p_ph_YF2 = mxGetField(ph,3,'ph_YF2');

p_ph_F3 = mxGetField(ph,4,'ph_F3');

p_ph_ZF3 = mxGetField(ph,5,'ph_ZF4');

p_ph_F4 = mxGetField(ph,6,'ph_F4');

p_ph_XF4 = mxGetField(ph,7,'ph_XF4');

p_ph_F5 = mxGetField(ph,8,'ph_F5');

p_ph_YF5 = mxGetField(ph,9,'ph_YF5');

p_ph_F6 = mxGetField(ph,10,'ph_F6');

p_ph_ZF6 = mxGetField(ph,11,'ph_ZF6');

}

目前,在尝试编译代码时出现以下错误:

错误:类型“int”的参数与类型“const char *”的参数不兼容

我已经浏览了MATLAB帮助和示例文件,但我很难找到/理解解决方案 .

任何帮助将不胜感激 .

谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值