I want to compile a MEX from a function that has the following code (MATLAB R2015a
):
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
I get the type mismatch
error between getIndFixed
and getIndRandom
at the line specified above:
Type mismatch: function_handle getIndFixed ~= getIndRandom.
- Is there a way around this problem?
- For instance, a way to specify that both functions have the same signature?
In C, the signature of the function would be:
int (*getInd)(int);
int getIndFixed(int);
int getIndRandom(int);
//...
getInd = getIndFixed;
getInd = getIndRandom;