0
我想从具有以下代码(MATLAB R2015a
)的函数的编译MEX:如何在MATLAB代码生成中为函数句柄指定函数签名?
function r = MyFunc(x,type)
ind = randi(numel(x), 1);
getInd = @getIndFixed;
if strcmpi(type, 'random')
ind = numel(x);
getInd = @getIndRandom; % error here
end
x(getInd(ind)) = 1;
end
function k = getIndFixed(n)
k = n;
end
function k = getIndRandom(n)
k = randi(n, 1);
end
我得到getIndFixed
和getIndRandom
之间的type mismatch
误差在上述规定的行:
类型不匹配:function_handle getIndFixed〜= getIndRandom。
- 是否有解决此问题的方法?
- 例如,一种指定两个函数具有相同签名的方法?
在C语言中,函数的签名是:
int (*getInd)(int);
int getIndFixed(int);
int getIndRandom(int);
//...
getInd = getIndFixed;
getInd = getIndRandom;