Convert function with struct input to mex while number of fields is unknown
1 次查看(过去 30 天)
显示 更早的评论
Hey guys,
I am trying to translate a matlab function of mine into a mex function but I am facing some issues.
The problem is, that the input into my function is a struct with sub-structs, each containing the same amount of fields, but an unknown amount of fields.
Inside the function I check that with:
if isfield(struct.substruct,'example')==1
...
else
...
end
For MatLab that is no problem, but for mex it is a problem, since I have to declare the number of fields while generating it and there is no possibility to do this like with arrays where you can say "up to ..."
So if the field does not exist, the number of fields is unepexted for mex and it doesnt run.
Is there any workaround for this??
Just bypassing the struct and simply giving the field values as inputs for my function doenst work either, since the field and its values do not exist sometimes.
The only way would be to write the funtction multiple times and check the number of fields before and then call with an if statement the function with the right number of input arguments. But for me it seems unlikely that this is the best way to solve my problem.
Best regards
4 个评论
James Tursa
2020-12-3
Do you have to use the Coder for this particular routine or will a hand-written mex routing work? Or maybe you can split your function into an interface routine that calls a work routine and hand-code only the interface routine. How complicated is the routine?
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!