Undefined function or variable 'inputParser' while using Matlab Function in Stateflow
显示 更早的评论
Hello all,
I'm using a matlab function within my stateflow diagram, however I'm getting the error "Undefined function or variable 'inputParser'". When I try to run the function within a .m file it works fine. I cannot find any limitations to inputParser usage in stateflow within the help files or by google.
Code:
function x = OK(i)
default = 1:50;
p = inputParser;
addOptional(p,'i',default);
parse(p,i);
if all(Input_Mux(i)== enumState.OK)
x = true;
else
x = false;
end
end
Does anyone know why this is failing?
6 个评论
Ameer Hamza
2020-6-4
In this function, the result of parse() is not being used. Why not remove those lines?
Christian Black
2020-6-4
Ameer Hamza
2020-6-5
It seems that the problem might be happening because the inputParser does not support code generation. You may try coder.extrinsic
coder.extrinsic('inputParser', 'addOptional', 'parse')
add this line at beginning of function definition
function x = OK(varargin)
coder.extrinsic('inputParser', 'addOptional', 'parse')
Input_mux = [1:100]; %Would normally be stateflow input, added here for ease.
default = 1:50;
p = inputParser;
addOptional(p,'i',default);
parse(p,varargin{:});
if all(Input_mux(p.Results.i)== 5)
x = true;
else
x = false;
end
end
Christian Black
2020-6-5
编辑:Christian Black
2020-6-5
Ameer Hamza
2020-6-5
Good that this solution worked. I have added this as an answer with modification to make it work. Thanks.
Christian Black
2020-7-2
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Event Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!